[cfe-dev] Spurious error

Csaba Raduly rcsaba at gmail.com
Fri May 27 04:08:30 PDT 2011


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

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

-- 
GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
The Tao of math: The numbers you can count are not the real numbers.
Life is complex, with real and imaginary parts.
"Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds
"People disagree with me. I just ignore them." -- Linus Torvalds



More information about the cfe-dev mailing list