Files
clang-p2996/clang/test/SemaCXX/condition.cpp
Richard Smith 8d06f42448 Improve 0-argument -Wvexing-parse diagnostic by adding notes with fix-its:
- If the declarator is at the start of a line, and the previous line contained
   another declarator and ended with a comma, then that comma was probably a
   typo for a semicolon:

   int n = 0, m = 1, l = 2, // k = 5;
   myImportantFunctionCall(); // oops!

 - If removing the parentheses would correctly initialize the object, then
   produce a note suggesting that fix.

 - Otherwise, if there is a simple initializer we can suggest which performs
   value-initialization, then provide a note suggesting a correction to that
   initializer.

Sema::Declarator now tracks the location of the comma prior to the declarator in
the declaration, if there is one, to facilitate providing the note. The code to
determine an appropriate initializer from the -Wuninitialized warning has been
factored out to allow use in both that and -Wvexing-parse.

llvm-svn: 148072
2012-01-12 23:53:29 +00:00

60 lines
2.8 KiB
C++

// RUN: %clang_cc1 -fsyntax-only -verify %s
void test() {
int x;
if (x) ++x;
if (int x=0) ++x;
typedef int arr[10];
while (arr x=0) ; // expected-error {{an array type is not allowed here}} expected-error {{array initializer must be an initializer list}}
while (int f()=0) ; // expected-warning {{interpreted as a function declaration}} expected-note {{initializer}} expected-error {{a function type is not allowed here}}
struct S {} s;
if (s) ++x; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}}
while (struct S x=s) ; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}}
do ; while (s); // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}}
for (;s;) ; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}}
switch (s) {} // expected-error {{statement requires expression of integer type ('struct S' invalid)}}
while (struct NewS *x=0) ;
while (struct S {} *x=0) ; // expected-error {{types may not be defined in conditions}}
while (struct {} *x=0) ; // expected-error {{types may not be defined in conditions}}
switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{cannot initialize}} \
// expected-warning{{enumeration value 'E' not handled in switch}}
if (int x=0) { // expected-note 2 {{previous definition is here}}
int x; // expected-error {{redefinition of 'x'}}
}
else
int x; // expected-error {{redefinition of 'x'}}
while (int x=0) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
while (int x=0) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
for (int x; int x=0; ) ; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
for (int x; ; ) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
for (; int x=0; ) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
for (; int x=0; ) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
switch (int x=0) { default: int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
}
int* get_int_ptr();
void test2() {
float *ip;
if (int *ip = ip) {
}
}
// Make sure we do function/array decay.
void test3() {
if ("help")
(void) 0;
if (test3) // expected-warning {{address of function 'test3' will always evaluate to 'true'}} \
expected-note {{prefix with the address-of operator to silence this warning}}
(void) 0;
}
void test4(bool (&x)(void)) {
while (x);
}