Spurious error

Hi all,

clang++ version 3.0 (trunk 132119)
Target: x86_64-unknown-linux-gnu
Thread model: posix

emits an error for the following code:

void puts(const char*);

struct X {};

void exx(X) {}

int main(int argc, char **argv)
{
  if (argc > 3)
    goto end;

  X x;
  exx(x);

  end:
    if (argc > 1) {
    for (int i = 0; i < argc; ++i)
    {
      puts(argv[i]);
    }
    }
    return 0;
}

c.cc:10:5: error: goto into protected scope
    goto end;
    ^
c.cc:12:5: note: jump bypasses variable initialization
  X x;
    ^

No errors from g++ version 4.5.0 20100604 [gcc-4_5-branch revision 160292]

Comeau online:

Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for ONLINE_EVALUATION_BETA2
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions

In strict mode, with -tused, Compile succeeded

clang has been outvoted 2:1 :slight_smile:

Csaba
P.S. compilation succeeds if the for loop is commented out.

Please file a bug at http://llvm.org/bugs

Sebastian

Submitted http://llvm.org/bugs/show_bug.cgi?id=10034

Csaba