This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/82239] New: Parentheses around constexpr template member break static_assert


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82239

            Bug ID: 82239
           Summary: Parentheses around constexpr template member break
                    static_assert
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: edolstra at gmail dot com
  Target Milestone: ---

With GCC 6.4 or 7.2, the following example fails to compile in C++14 mode:

=== start ===
template<typename T>
struct C {
   static constexpr int x = 5;
   void f()
   {
      static_assert(0 < x, "x"); // ok
      static_assert(0 < (x), "x"); // fails
      static_assert(true || (0 < x), "x"); // ok
      static_assert(true || (0 < (x)), "x"); // fails
   }
};
=== end ===

$ g++ -c -std=c++14 foo.cc
foo.cc: In member function ‘void C<T>::f()’:
foo.cc:7:7: error: non-constant condition for static assertion
       static_assert(0 < (x), "x"); // fails
       ^~~~~~~~~~~~~
foo.cc:9:7: error: non-constant condition for static assertion
       static_assert(true || (0 < (x)), "x"); // fails
       ^~~~~~~~~~~~~

OTOH, -std=c++11 works fine. GCC 5.4 with -std=c++14 also compiles.

Also, removing "template<typename T>" or moving the definition of "x" out of
the template makes it compile.

Tested on x86_64-linux (NixOS). Compiler info:

$ g++ -v
Using built-in specs.                                                           
COLLECT_GCC=/nix/store/l9nq5bvqgjngqhlq7ks6cg0bdizn2l0v-gcc-7.2.0/bin/g++       
COLLECT_LTO_WRAPPER=/nix/store/l9nq5bvqgjngqhlq7ks6cg0bdizn2l0v-gcc-7.2.0/libexec/gcc/x86_64-unknown-linux-gnu/7.2.0/lto-wrapper 
Target: x86_64-unknown-linux-gnu                                                
Configured with:                                                                
Thread model: posix                                                             
gcc version 7.2.0 (GCC)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]