[cfe-dev] test case for stmt.label.

sashan sashan at zenskg.net
Sat Nov 27 21:27:40 PST 2010


Hi

I felt like getting my feet wet with clang so I've attached a test case for
stmt.label in test/CXX/stmt.stmt/stmt.label.

Additionally I think that there's a bug in the clang error reporting since it
incorrectly identifies the location of the previous definition of the 'default'
label. If you compile the attached file with:

clang++ -fsyntax-only

You'll see these errors:

test/CXX/stmt.stmt/stmt.label/p1.cpp:22:5: error: multiple default labels in one switch
    default:; // expected-error{{multiple default labels in one switch}}
    ^
test/CXX/stmt.stmt/stmt.label/p1.cpp:23:5: note: previous case defined here
    default:; // expected-note{{previous case defined here}}
    ^
Note that clang thinks that the line location of the previous 'default' label is
after the first place the label 'default' is defined.  I think the note and
error messages should be swapped around.

-------------- next part --------------
// RUN: %clang_cc1 -fsyntax-only -verify %s

void f()
{
  int x = 0;
  goto label1;

label1: // expected-note{{previous definition is here}}
  x = 1;
  goto label2; // expected-error{{use of undeclared label 'label2'}}

label1: // expected-error{{redefinition of label ''label1''}}
  x = 2;
}

void h()
{
  int x = 0;
  switch (x)
  {
    case 1:;
    default:; // expected-error{{multiple default labels in one switch}}
    default:; // expected-note{{previous case defined here}}
  }
}


More information about the cfe-dev mailing list