public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108324] New: Temporary not bound to reference in default member initializer destroyed early from parenthesized expression-list initialization of aggregate
@ 2023-01-07  5:23 hstong at ca dot ibm.com
  2023-01-07 11:55 ` [Bug c++/108324] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: hstong at ca dot ibm.com @ 2023-01-07  5:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108324
           Summary: Temporary not bound to reference in default member
                    initializer destroyed early from parenthesized
                    expression-list initialization of aggregate
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: rejects-valid, wrong-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hstong at ca dot ibm.com
  Target Milestone: ---

While the lifetime-extension rules for temporaries bound to a reference member
differ between braced and parenthesized aggregate initialization, the
full-expression associated with default member initializers used in the
aggregate initialization are the same in both cases ([intro.execution]).

It seems GCC thinks that the parenthesized expression-list case causes
destruction of temporaries from the default member initializer at an earlier
point than in the braced initialization case.

ICC does not have this problem (at least when doing constant expression
evaluation).

Online compiler link: https://godbolt.org/z/aPhffr7xT

### SOURCE (<stdin>):
struct A {
  constexpr A(int x) : x(x) {}
  constexpr ~A() { x = 13; }
  int x;
  constexpr A &ref() { return *this; }
};
struct B {
  const A *ap = &A(42).ref();
};
constexpr int f() { return B{}.ap->x; }
constexpr int g() { return B().ap->x; }

extern char q[f()];
extern char q[42];
extern char k[g()];
extern char k[42];


### COMPILER INVOCATION COMMAND:
g++ -fsyntax-only -std=c++2b -xc++ -


### ACTUAL OUTPUT:
<stdin>:15:16: error: size of array 'k' is not an integral constant-expression
<stdin>:16:13: error: conflicting declaration 'char k [42]'
<stdin>:15:13: note: previous declaration as 'char k [1]'


### 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/13.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 13.0.0 20230106 (experimental) (GCC)

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

* [Bug c++/108324] Temporary not bound to reference in default member initializer destroyed early from parenthesized expression-list initialization of aggregate
  2023-01-07  5:23 [Bug c++/108324] New: Temporary not bound to reference in default member initializer destroyed early from parenthesized expression-list initialization of aggregate hstong at ca dot ibm.com
@ 2023-01-07 11:55 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-07 11:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
MSVC rejects it for the same reason as GCC:

<source>(15): error C2131: expression did not evaluate to a constant
<source>(11): note: a non-constant (sub-)expression was encountered
<source>(16): error C2369: 'k': redefinition; different subscripts
<source>(15): note: see declaration of 'k'

Note clang rejects both array definitions thinking it is a VLA ....

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

end of thread, other threads:[~2023-01-07 11:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-07  5:23 [Bug c++/108324] New: Temporary not bound to reference in default member initializer destroyed early from parenthesized expression-list initialization of aggregate hstong at ca dot ibm.com
2023-01-07 11:55 ` [Bug c++/108324] " pinskia at gcc dot gnu.org

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).