From efe703618c248ecaeb07c8cd89114abb41506171 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 19 Nov 2020 09:13:24 -0500 Subject: [PATCH] Googletest export Update note on static const data members for C++17. Using `constexpr` provides a tidier solution, where applicable. PiperOrigin-RevId: 343276402 --- googletest/docs/faq.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/googletest/docs/faq.md b/googletest/docs/faq.md index 3ece95bc..b59e1a0d 100644 --- a/googletest/docs/faq.md +++ b/googletest/docs/faq.md @@ -217,6 +217,18 @@ particular, using it in googletest comparison assertions (`EXPECT_EQ`, etc) will generate an "undefined reference" linker error. The fact that "it used to work" doesn't mean it's valid. It just means that you were lucky. :-) +If the declaration of the static data member is `constexpr` then it is +implicitly an `inline` definition, and a separate definition in `foo.cc` is not +needed: + +```c++ +// foo.h +class Foo { + ... + static constexpr int kBar = 100; // Defines kBar, no need to do it in foo.cc. +}; +``` + ## Can I derive a test fixture from another? Yes.