[cfe-users] is this compiller error

Richard Smith via cfe-users cfe-users at lists.llvm.org
Wed Feb 12 05:21:26 PST 2020


On Fri, 7 Feb 2020 at 19:51, FRANČEK PRIJATELJ via cfe-users <
cfe-users at lists.llvm.org> wrote:

> /*
>
> Following code compiled with clang-cl on win10 generates 2 errors
> (while the same code compiled with MS cl compiles):
>
> t1.cpp(12,35): error: in-class initializer for static data member is not
> a constant expression
>          static const int64_t MIN_VALUE = -0x8000000000000000LL;
>                                           ^~~~~~~~~~~~~~~~~~~~~
> t1.cpp(15,39): error: in-class initializer for static data member is not
> a constant expression
>      static const int64_t MIN_VALUE1 = -9223372036854775808LL;
>                                        ^~~~~~~~~~~~~~~~~~~~~~
> 2 errors generated.
>

These expressions have undefined behavior due to exhibiting signed
overflow, and so are non-constant in C++11 onwards.

*/
>
> #include <string>
>
> static const int64_t MAX_VALUE = 0x7fffffffffffffffLL;
> static const int64_t MIN_VALUE = -0x8000000000000000LL;
>
> static const int64_t MAX_VALUE1 = 9223372036854775807LL;
> static const int64_t MIN_VALUE1 = -9223372036854775808LL;
>
>
> class X  {
>      static const int64_t MAX_VALUE = 0x7fffffffffffffffLL;
>      static const int64_t MIN_VALUE = -0x8000000000000000LL;
>
>      static const int64_t MAX_VALUE1 = 9223372036854775807LL;
>      static const int64_t MIN_VALUE1 = -9223372036854775808LL;
> };
>
>
> _______________________________________________
> cfe-users mailing list
> cfe-users at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20200212/b410ca55/attachment.html>


More information about the cfe-users mailing list