Skip to content

Statement expressions allow jumping past initialization #138257

Open
@AaronBallman

Description

@AaronBallman

In C++, both Clang and GCC diagnose when a jump statement will jump over an initialization. However, statement expressions seem to be allowed to do so:

void f(void) {          

 for (int i=({ goto ouch; int x = 10; x;});i<0;++i)

ouch:
  ;
}

void g(void) {          
  ({ 
    goto ouch;  
    int i = 12;
  });

ouch:
  ;
}

https://godbolt.org/z/Eda59KqPT

It's possible that this is intentional given that statement expressions tend to be hidden behind macros, but this seems inconsistent and somewhat dangerous to allow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions