https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71564
Bug ID: 71564 Summary: label inside a lambda conflicts (?) with another one outside it Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: lh_mouse at 126 dot com Target Milestone: --- This code fails to compile with any current version of g++ from 4.7 to 7.0: ``` int main(){ _infinite_retry: [=]{ _infinite_retry: goto _infinite_retry; // go to the second _infinite_retry. }(); goto _infinite_retry; // go to the first _infinite_retry. } ``` D:\Desktop>g++ test.cpp -Wall test.cpp: In function 'int main()': test.cpp:2:2: warning: label '_infinite_retry' defined but not used [-Wunused-label] _infinite_retry: ^~~~~~~~~~~~~~~ test.cpp:7:8: error: label '_infinite_retry' used but not defined goto _infinite_retry; // go to the outer _infinite_retry. ^~~~~~~~~~~~~~~ Quoting from the standard: ``` ISO/IEC WG21 N4582 5.1.2 Lambda expressions [expr.prim.lambda] 8 The lambda-expression’s compound-statement yields the function-body (8.4) of the function call operator, ... 3.3.5 Function scope [basic.funscope] 1 Labels (6.1) have function scope and may be used anywhere in the function in which they are declared. Only labels have function scope. ``` The compound statement of a lambda expression is a function body thus it creates a function scope. The second label should reside in that scope but somehow nullifies the first one, causing the second goto statement to fail to find the first label.