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

            Bug ID: 116011
           Summary: Bogus template redefinition error between
                    pointer-to-member &T::x versus pointer &(T::x)
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hstong at ca dot ibm.com
  Target Milestone: ---

In the following, the definitions of two template functions that differ in the
presence of parentheses around the operand to a unary & operator are diagnosed
by GCC as being duplicate definitions of the same function.


### SOURCE (<stdin>):
struct A { int x; };

char q(int *);
short q(int A::*);

template <typename T>
constexpr int f(char (*)[sizeof(q(&T::x))]) { return 1; }

template <typename T>
constexpr int f(char (*)[sizeof(q(&(T::x)))]) { return 2; }

constexpr int g(char (*p)[sizeof(char)] = 0) { return f<A>(p); }
constexpr int h(char (*p)[sizeof(short)] = 0) { return f<A>(p); }

static_assert(g() == 2);
static_assert(h() == 1);


### COMPILER INVOCATION:
g++ -fsyntax-only -std=c++11 -xc++ -


### ACTUAL OUTPUT:
<stdin>:10:15: error: redefinition of 'template<class T> constexpr int f(char
(*)[sizeof (q((& T::x)))])'
<stdin>:7:15: note: 'template<class T> constexpr int f(char (*)[sizeof (q((&
T::x)))])' previously declared here
<stdin>: In function 'constexpr int g(char (*)[1])':
<stdin>:12:60: error: cannot convert 'char (*)[1]' to 'char (*)[2]'
<stdin>:7:17: note:   initializing argument 1 of 'constexpr int f(char
(*)[sizeof (q((& T::x)))]) [with T = A]'
<stdin>:12:64: error: body of 'constexpr' function 'constexpr int g(char
(*)[1])' not a return-statement
<stdin>: At global scope:
<stdin>:15:19: error: non-constant condition for static assertion
<stdin>:15:16: error: 'constexpr int g(char (*)[1])' called in a constant
expression
<stdin>:12:15: note: 'constexpr int g(char (*)[1])' declared here


### EXPECTED OUTPUT:
(clean compile)


### COMPILER VERSION INFO (g++ -v):
Using built-in specs.
COLLECT_GCC=/opt/wandbox/gcc-head/bin/g++
COLLECT_LTO_WRAPPER=/opt/wandbox/gcc-head/libexec/gcc/x86_64-pc-linux-gnu/15.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../source/configure --prefix=/opt/wandbox/gcc-head
--enable-languages=c,c++ --disable-multilib --without-ppl --without-cloog-ppl
--enable-checking=release --disable-nls --enable-lto
LDFLAGS=-Wl,-rpath,/opt/wandbox/gcc-head/lib,-rpath,/opt/wandbox/gcc-head/lib64,-rpath,/opt/wandbox/gcc-head/lib32
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20240719 (experimental) (GCC)

Reply via email to