public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/116011] New: Bogus template redefinition error between pointer-to-member &T::x versus pointer &(T::x)
@ 2024-07-20  5:21 hstong at ca dot ibm.com
  2024-07-20  5:26 ` [Bug c++/116011] " pinskia at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: hstong at ca dot ibm.com @ 2024-07-20  5:21 UTC (permalink / raw)
  To: gcc-bugs

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)

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-07-20 19:57 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-20  5:21 [Bug c++/116011] New: Bogus template redefinition error between pointer-to-member &T::x versus pointer &(T::x) hstong at ca dot ibm.com
2024-07-20  5:26 ` [Bug c++/116011] " pinskia at gcc dot gnu.org
2024-07-20  5:35 ` hstong at ca dot ibm.com
2024-07-20  5:44 ` pinskia at gcc dot gnu.org
2024-07-20  5:56 ` [Bug c++/116011] accepting &(T::x) as a pointer to member in an unevulated context and not treating it differently from &T::x hstong at ca dot ibm.com
2024-07-20 18:54 ` [Bug c++/116011] Template declaration matching does not differentiate between &(T::x) and &T::x; only the latter can form a pointer to member hstong at ca dot ibm.com
2024-07-20 18:57 ` pinskia at gcc dot gnu.org
2024-07-20 19:01 ` [Bug c++/116011] accepting &(T::x) as a pointer to member in an unevulated context and not treating it differently from &T::x pinskia at gcc dot gnu.org
2024-07-20 19:39 ` hstong at ca dot ibm.com
2024-07-20 19:44 ` pinskia at gcc dot gnu.org
2024-07-20 19:57 ` hstong at ca dot ibm.com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).