When i have following code: #include <stdint.h> static constexpr uint8_t small_global = 0xFFFFFFFF; class A { static constexpr uint8_t small_within_class = 0xFFFFFFFF; }; template<typename T> class B { static constexpr uint8_t small_within_templated_class = 0xFFFFFFFF; }; B<int> b; It only produces warnings for first two cases. Online compiler with test case: https://goo.gl/aGL0n4
Confirmed.
I don't think the test case necessarily demonstrates a bug. The implicit instantiation of B<int> that's triggered by the definition of an object of the specialization "causes the implicit instantiation of the declarations, but not of the definitions, [...] of the class [...] static data members; and it causes the implicit instantiation of the definitions of unscoped member enumerations and member anonymous unions." That being said, I think the bug can be reproduced by instantiating (e.g., by virtue of using) B<int>::small_within_templated_class, for example like so: template <typename T> class B { static constexpr uint8_t small_within_templated_class = 0xFFFFFFFF; }; constexpr uint8_t i = B<int>::small_within_templated_class;
> template <typename T> > class B { > static constexpr uint8_t small_within_templated_class = 0xFFFFFFFF; > }; > > constexpr uint8_t i = B<int>::small_within_templated_class; "s/class/struct/" to make member public. This case is NOT warned. But clang++ warns: ~~~ pr69138-1.cpp:4:59: warning: implicit conversion from 'unsigned int' to 'const uint8_t' (aka 'const unsigned char') changes value from 4294967295 to 255 [-Wconstant-conversion] static constexpr uint8_t small_within_templated_class = 0xFFFFFFFF; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~ 1 warning generated. ~~~
Created attachment 40950 [details] Another way to show this bug This test case also exploits this bug. In this lim<long> should be the same as limlong, but g++ (trunk) only warns about the latter: ~~~ pr69138-2.cpp: In function 'long unsigned int limlong(bool)': pr69138-2.cpp:23:16: warning: integer overflow in expression [-Woverflow] return b ? -limits<long>::min : limits<long>::max; ~~~ No warnings generated for lim<long>(bool).