I have a header file containing multiple constexpr variables like the following:
namespace AAA {
constexpr const char* A = "abc";
constexpr std::array B = {"aaa", "bbb"};
}
namespace BBB {
constexpr const char* C = "def";
constexpr std::array D = {"ccc", "ddd"};
constexpr const char* E = "efg";
}
This header is used in multiple projects (separate parts of the code). When trying to build, I get something like:
error: 'AAA::B' defined but not used.
I do not get the error for BBB::D
, although neither of the variables are used in the translation units that yield the error.
If I change the third line to
constexpr std::array<const char*, 2> B = {"aaa", "bbb"};
compilation goes through (although I have not changed constexpr std::array D = {"ccc", "ddd"};
).
Adding static
keyword does not affect the outcome. Adding template parameters for BBB::D
and not adding it for AAA::B
does not help either.
Any ideas what the reason is?