2015-11-12 03:34:47 +08:00
|
|
|
// RUN: %clang_cc1 -verify -x c++ -std=c++98 %s
|
|
|
|
// RUN: not %clang_cc1 -fdiagnostics-parseable-fixits -x c++ -std=c++98 %s 2>&1 | FileCheck %s
|
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-13 07:53:29 +08:00
|
|
|
|
|
|
|
struct S {
|
|
|
|
int n;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct T {
|
|
|
|
T();
|
2012-07-31 05:30:52 +08:00
|
|
|
T(S, S);
|
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-13 07:53:29 +08:00
|
|
|
int n;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct U {
|
|
|
|
~U();
|
|
|
|
int n;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct V {
|
|
|
|
~V();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct W : V {
|
|
|
|
};
|
|
|
|
|
|
|
|
struct X : U {
|
|
|
|
};
|
|
|
|
|
|
|
|
int F1();
|
|
|
|
S F2();
|
|
|
|
|
|
|
|
namespace N {
|
|
|
|
void test() {
|
2012-07-31 05:30:52 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{35:9-35:11}:" = {}"
|
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-13 07:53:29 +08:00
|
|
|
S s1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
|
|
|
|
|
2012-07-31 05:30:52 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{39:9-39:10}:";"
|
|
|
|
// CHECK: fix-it:"{{.*}}":{40:7-40:9}:" = {}"
|
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-13 07:53:29 +08:00
|
|
|
S s2, // expected-note {{change this ',' to a ';' to call 'F2'}}
|
|
|
|
F2(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
|
|
|
|
|
|
|
|
// CHECK: fix-it:"{{.*}}":{44:9-44:11}:""
|
2012-07-31 05:30:52 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{45:9-45:11}:""
|
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-13 07:53:29 +08:00
|
|
|
T t1(), // expected-warning {{function declaration}} expected-note {{remove parentheses}}
|
|
|
|
t2(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
|
|
|
|
|
2012-07-31 05:30:52 +08:00
|
|
|
// Suggest parentheses only around the first argument.
|
|
|
|
// CHECK: fix-it:"{{.*}}":{50:10-50:10}:"("
|
|
|
|
// CHECK: fix-it:"{{.*}}":{50:13-50:13}:")"
|
|
|
|
T t3(S(), S()); // expected-warning {{disambiguated as a function declaration}} expected-note {{add a pair of parentheses}}
|
|
|
|
|
|
|
|
// Check fixit position for pathological case
|
|
|
|
// CHECK: fix-it:"{{.*}}":{56:11-56:11}:"("
|
|
|
|
// CHECK: fix-it:"{{.*}}":{56:20-56:20}:")"
|
|
|
|
float k[1];
|
|
|
|
int l(int(k[0])); // expected-warning {{disambiguated as a function declaration}} expected-note {{add a pair of parentheses}}
|
|
|
|
|
|
|
|
// Don't emit warning and fixit because this must be a function declaration due to void return type.
|
|
|
|
typedef void VO;
|
|
|
|
VO m(int (*p)[4]);
|
|
|
|
|
|
|
|
// Don't emit warning and fixit because direct initializer is not permitted here.
|
2016-06-24 03:02:52 +08:00
|
|
|
if (int n(int())){} // expected-error {{function type is not allowed here}}
|
2012-07-31 05:30:52 +08:00
|
|
|
|
|
|
|
// CHECK: fix-it:"{{.*}}":{66:8-66:10}:" = {}"
|
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-13 07:53:29 +08:00
|
|
|
U u(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
|
|
|
|
|
2012-07-31 05:30:52 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{69:8-69:10}:""
|
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-13 07:53:29 +08:00
|
|
|
V v(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
|
|
|
|
|
2012-07-31 05:30:52 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{72:8-72:10}:""
|
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-13 07:53:29 +08:00
|
|
|
W w(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
|
|
|
|
|
|
|
|
// TODO: Removing the parens here would not initialize U::n.
|
|
|
|
// Maybe suggest an " = X()" initializer for this case?
|
|
|
|
// Maybe suggest removing the parens anyway?
|
|
|
|
X x(); // expected-warning {{function declaration}}
|
|
|
|
|
2012-07-31 05:30:52 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{80:11-80:13}:" = 0"
|
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-13 07:53:29 +08:00
|
|
|
int n1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
|
|
|
|
|
2012-07-31 05:30:52 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{84:11-84:12}:";"
|
|
|
|
// CHECK: fix-it:"{{.*}}":{85:7-85:9}:" = 0"
|
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-13 07:53:29 +08:00
|
|
|
int n2, // expected-note {{change this ',' to a ';' to call 'F1'}}
|
|
|
|
F1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
|
|
|
|
|
2012-07-31 05:30:52 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{88:13-88:15}:" = 0.0"
|
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-13 07:53:29 +08:00
|
|
|
double d(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
|
|
|
|
|
|
|
|
typedef void *Ptr;
|
|
|
|
|
2012-07-31 05:30:52 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{93:10-93:12}:" = 0"
|
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-13 07:53:29 +08:00
|
|
|
Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
|
|
|
|
|
|
|
|
#define NULL 0
|
2012-07-31 05:30:52 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{97:10-97:12}:" = NULL"
|
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-13 07:53:29 +08:00
|
|
|
Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
|
2012-03-18 10:56:47 +08:00
|
|
|
|
2012-07-31 05:30:52 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{100:11-100:13}:" = false"
|
2012-03-18 10:56:47 +08:00
|
|
|
bool b(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
|
|
|
|
|
2012-07-31 05:30:52 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{103:11-103:13}:" = '\\0'"
|
2012-03-18 10:56:47 +08:00
|
|
|
char c(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
|
|
|
|
|
2012-07-31 05:30:52 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{106:15-106:17}:" = L'\\0'"
|
2012-03-18 10:56:47 +08:00
|
|
|
wchar_t wc(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
|
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-13 07:53:29 +08:00
|
|
|
}
|
|
|
|
}
|
2017-09-30 07:57:25 +08:00
|
|
|
|
|
|
|
namespace RedundantParens {
|
|
|
|
struct Y {
|
|
|
|
Y();
|
|
|
|
Y(int);
|
|
|
|
~Y();
|
|
|
|
};
|
|
|
|
int n;
|
|
|
|
|
|
|
|
void test() {
|
|
|
|
// CHECK: add a variable name
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE+7]]:4-[[@LINE+7]]:4}:" varname"
|
|
|
|
// CHECK: add enclosing parentheses
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE+5]]:3-[[@LINE+5]]:3}:"("
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE+4]]:7-[[@LINE+4]]:7}:")"
|
|
|
|
// CHECK: remove parentheses
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE+2]]:4-[[@LINE+2]]:5}:" "
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:6-[[@LINE+1]]:7}:""
|
|
|
|
Y(n); // expected-warning {{declaration of variable named 'n'}} expected-note 3{{}}
|
|
|
|
}
|
|
|
|
}
|