Bug 79367 - ICE with decltype of VLA in lambda
Summary: ICE with decltype of VLA in lambda
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, rejects-valid
Depends on:
Blocks: C++VLA lambdas
  Show dependency treegraph
 
Reported: 2017-02-03 19:45 UTC by Zhendong Su
Modified: 2025-04-17 16:12 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-04-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zhendong Su 2017-02-03 19:45:31 UTC
All 4.8.x and later ICE, but not 4.7.x.  

The code is correctly accepted by Clang. 


$ g++-trunk -v
Using built-in specs.
COLLECT_GCC=g++-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/7.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto --prefix=/usr/local/gcc-trunk --disable-bootstrap
Thread model: posix
gcc version 7.0.1 20170203 (experimental) [trunk revision 245148] (GCC) 
$ 
$ clang++ -c -std=c++11 small.cpp
$ 
$ g++-trunk -c -std=c++11 small.cpp
small.cpp: In lambda function:
small.cpp:6:5: error: Local declaration from a different function
   [&] { decltype (b) c; } ();
     ^
D.2056
small.cpp:6:22: note: in statement
   [&] { decltype (b) c; } ();
                      ^
_1 = (sizetype) D.2056;
small.cpp:6:5: error: Local declaration from a different function
   [&] { decltype (b) c; } ();
     ^
D.2056
small.cpp:6:22: note: in statement
   [&] { decltype (b) c; } ();
                      ^
_5 = (sizetype) D.2056;
small.cpp:6:5: internal compiler error: verify_gimple failed
   [&] { decltype (b) c; } ();
     ^
0xe5e15d verify_gimple_in_cfg(function*, bool)
	../../gcc-source-trunk/gcc/tree-cfg.c:5266
0xd3ac27 execute_function_todo
	../../gcc-source-trunk/gcc/passes.c:1966
0xd3b595 execute_todo
	../../gcc-source-trunk/gcc/passes.c:2016
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
$ 


-----------------------------------


int a = 1;

void foo ()
{
  int b[a];
  [&] { decltype (b) c; } ();
}
Comment 1 Martin Liška 2017-02-03 21:48:33 UTC
Confirmed, also 4.7.0 (with checking enabled) ICEs.
Comment 2 Paolo Carlini 2017-10-10 17:26:49 UTC
Related to PR60230 and PR64000.
Comment 3 Jason Merrill 2019-03-25 21:15:48 UTC
This is not valid C++11 code: b (and thus c) are VLAs, which are not part of any C++ standard.  But we should still accept it.

G++ currently has trouble with outer VLA types that aren't simple "array of runtime bound" from the cancelled Arrays TS.
Comment 4 Marek Polacek 2020-07-23 17:36:55 UTC
Since r10-6389 we no longer crash but issue an error:

79367.C: In lambda function:
79367.C:6:22: error: ‘c’ declared as reference but not initialized
    6 |   [&] { decltype (b) c; } ();
      |                      ^