Improvements to vexing-parse warnings. Make the no-parameters case more
accurate by asking the parser whether there was an ambiguity rather than trying
to reverse-engineer it from the DeclSpec. Make the with-parameters case have
better diagnostics by using semantic information to drive the warning,
improving the diagnostics and adding a fixit.

Patch by Nikola Smiljanic. Some minor changes by me to suppress diagnostics for
declarations of the form 'T (*x)(...)', which seem to have a very high false
positive rate, and to reduce indentation in 'warnAboutAmbiguousFunction'.

llvm-svn: 160998
diff --git a/clang/test/FixIt/fixit-vexing-parse.cpp b/clang/test/FixIt/fixit-vexing-parse.cpp
index 8450590..dd0f873 100644
--- a/clang/test/FixIt/fixit-vexing-parse.cpp
+++ b/clang/test/FixIt/fixit-vexing-parse.cpp
@@ -7,6 +7,7 @@
 
 struct T {
   T();
+  T(S, S);
   int n;
 };
 
@@ -30,26 +31,44 @@
 
 namespace N {
   void test() {
-    // CHECK: fix-it:"{{.*}}":{34:9-34:11}:" = {}"
+    // CHECK: fix-it:"{{.*}}":{35:9-35:11}:" = {}"
     S s1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
 
-    // CHECK: fix-it:"{{.*}}":{38:9-38:10}:";"
-    // CHECK: fix-it:"{{.*}}":{39:7-39:9}:" = {}"
+    // CHECK: fix-it:"{{.*}}":{39:9-39:10}:";"
+    // CHECK: fix-it:"{{.*}}":{40:7-40:9}:" = {}"
     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:"{{.*}}":{43:9-43:11}:""
     // CHECK: fix-it:"{{.*}}":{44:9-44:11}:""
+    // CHECK: fix-it:"{{.*}}":{45:9-45:11}:""
     T t1(), // expected-warning {{function declaration}} expected-note {{remove parentheses}}
       t2(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
 
-    // CHECK: fix-it:"{{.*}}":{47:8-47:10}:" = {}"
+    // 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.
+    if (int n(int())){} // expected-error {{function type is not allowed here}} expected-error {{condition must have an initializer}}
+
+    // CHECK: fix-it:"{{.*}}":{66:8-66:10}:" = {}"
     U u(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
 
-    // CHECK: fix-it:"{{.*}}":{50:8-50:10}:""
+    // CHECK: fix-it:"{{.*}}":{69:8-69:10}:""
     V v(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
 
-    // CHECK: fix-it:"{{.*}}":{53:8-53:10}:""
+    // CHECK: fix-it:"{{.*}}":{72:8-72:10}:""
     W w(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
 
     // TODO: Removing the parens here would not initialize U::n.
@@ -57,33 +76,33 @@
     // Maybe suggest removing the parens anyway?
     X x(); // expected-warning {{function declaration}}
 
-    // CHECK: fix-it:"{{.*}}":{61:11-61:13}:" = 0"
+    // CHECK: fix-it:"{{.*}}":{80:11-80:13}:" = 0"
     int n1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
 
-    // CHECK: fix-it:"{{.*}}":{65:11-65:12}:";"
-    // CHECK: fix-it:"{{.*}}":{66:7-66:9}:" = 0"
+    // CHECK: fix-it:"{{.*}}":{84:11-84:12}:";"
+    // CHECK: fix-it:"{{.*}}":{85:7-85:9}:" = 0"
     int n2, // expected-note {{change this ',' to a ';' to call 'F1'}}
     F1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
 
-    // CHECK: fix-it:"{{.*}}":{69:13-69:15}:" = 0.0"
+    // CHECK: fix-it:"{{.*}}":{88:13-88:15}:" = 0.0"
     double d(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
 
     typedef void *Ptr;
 
-    // CHECK: fix-it:"{{.*}}":{74:10-74:12}:" = 0"
+    // CHECK: fix-it:"{{.*}}":{93:10-93:12}:" = 0"
     Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
 
 #define NULL 0
-    // CHECK: fix-it:"{{.*}}":{78:10-78:12}:" = NULL"
+    // CHECK: fix-it:"{{.*}}":{97:10-97:12}:" = NULL"
     Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
 
-    // CHECK: fix-it:"{{.*}}":{81:11-81:13}:" = false"
+    // CHECK: fix-it:"{{.*}}":{100:11-100:13}:" = false"
     bool b(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
 
-    // CHECK: fix-it:"{{.*}}":{84:11-84:13}:" = '\\0'"
+    // CHECK: fix-it:"{{.*}}":{103:11-103:13}:" = '\\0'"
     char c(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
 
-    // CHECK: fix-it:"{{.*}}":{87:15-87:17}:" = L'\\0'"
+    // CHECK: fix-it:"{{.*}}":{106:15-106:17}:" = L'\\0'"
     wchar_t wc(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
   }
 }
diff --git a/clang/test/Parser/objcxx11-attributes.mm b/clang/test/Parser/objcxx11-attributes.mm
index 0c91392..1b9bf66 100644
--- a/clang/test/Parser/objcxx11-attributes.mm
+++ b/clang/test/Parser/objcxx11-attributes.mm
@@ -35,7 +35,8 @@
   [[class, test(foo 'x' bar),,,]];
   [[bitand, noreturn]]; // expected-warning {{attribute noreturn cannot be specified on a statement}}
 
-  [[noreturn]]int(e)();
+  // FIXME: Suppress vexing parse warning
+  [[noreturn]]int(e)(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} 
   int e2(); // expected-warning {{interpreted as a function declaration}} expected-note{{}}
 
   // A function taking a noreturn function.
diff --git a/clang/test/SemaCXX/condition.cpp b/clang/test/SemaCXX/condition.cpp
index 993f8e1..ec5eb17 100644
--- a/clang/test/SemaCXX/condition.cpp
+++ b/clang/test/SemaCXX/condition.cpp
@@ -7,7 +7,7 @@
 
   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}}
+  while (int f()=0) ; // 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'}}
diff --git a/clang/test/SemaCXX/dcl_ambig_res.cpp b/clang/test/SemaCXX/dcl_ambig_res.cpp
index fa71b11..08867c0 100644
--- a/clang/test/SemaCXX/dcl_ambig_res.cpp
+++ b/clang/test/SemaCXX/dcl_ambig_res.cpp
@@ -10,9 +10,9 @@
 
 void foo(double a) 
 { 
-  S w(int(a)); // expected-warning{{disambiguated}}
+  S w(int(a)); // expected-warning{{disambiguated as a function declaration}} expected-note{{add a pair of parentheses}} 
   w(17);
-  S x1(int()); // expected-warning{{disambiguated}}
+  S x1(int()); // expected-warning{{disambiguated as a function declaration}} expected-note{{add a pair of parentheses}} 
   x1(&returns_an_int);
   S y((int)a); 
   y.bar();
@@ -69,7 +69,7 @@
   static bool const value = false;
 };
 int foo8() {
-  int v(int(S5::value)); // expected-warning{{disambiguated}} expected-error{{parameter declarator cannot be qualified}}
+  int v(int(S5::value)); // expected-warning{{disambiguated as a function declaration}} expected-note{{add a pair of parentheses}} expected-error{{parameter declarator cannot be qualified}}
 }
 
 template<typename T>
diff --git a/clang/test/SemaCXX/decl-expr-ambiguity.cpp b/clang/test/SemaCXX/decl-expr-ambiguity.cpp
index ab1a2b5..7ee699c 100644
--- a/clang/test/SemaCXX/decl-expr-ambiguity.cpp
+++ b/clang/test/SemaCXX/decl-expr-ambiguity.cpp
@@ -22,10 +22,10 @@
   (int())1; // expected-error {{C-style cast from 'int' to 'int ()' is not allowed}}
 
   // Declarations.
-  int fd(T(a)); // expected-warning {{parentheses were disambiguated as a function declarator}}
-  T(*d)(int(p)); // expected-warning {{parentheses were disambiguated as a function declarator}} expected-note {{previous definition is here}}
-  typedef T(*td)(int(p));
-  extern T(*tp)(int(p));
+  int fd(T(a)); // expected-warning {{disambiguated as a function declaration}} expected-note{{add a pair of parentheses}}
+  T(*d)(int(p)); // expected-note {{previous}}
+  typedef T td(int(p));
+  extern T tp(int(p));
   T d3(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}}
   T d3v(void);
   typedef T d3t();
diff --git a/clang/test/SemaObjCXX/protocol-lookup.mm b/clang/test/SemaObjCXX/protocol-lookup.mm
index bd8444c..e8abf6c 100644
--- a/clang/test/SemaObjCXX/protocol-lookup.mm
+++ b/clang/test/SemaObjCXX/protocol-lookup.mm
@@ -52,5 +52,5 @@
 void rdar8575095(id a) {
   [id<NSObject>(a) retain];
   id<NSObject> x(id<NSObject>(0));
-  id<NSObject> x2(id<NSObject>(y)); // expected-warning{{parentheses were disambiguated as a function declarator}}
+  id<NSObject> x2(id<NSObject>(y)); // expected-warning{{disambiguated as a function declaration}} expected-note{{add a pair of parentheses}}
 }
diff --git a/clang/test/SemaTemplate/typename-specifier.cpp b/clang/test/SemaTemplate/typename-specifier.cpp
index 15c13e3..733dc7f 100644
--- a/clang/test/SemaTemplate/typename-specifier.cpp
+++ b/clang/test/SemaTemplate/typename-specifier.cpp
@@ -22,8 +22,8 @@
 // expected-warning{{'typename' occurs outside of a template}}
 
 void test(double d) {
-  typename N::A::type f(typename N::A::type(a)); // expected-warning{{parentheses were disambiguated as a function declarator}} \
-  // expected-warning 2{{'typename' occurs outside of a template}}
+  typename N::A::type f(typename N::A::type(a)); // expected-warning{{disambiguated as a function declaration}} \
+  // expected-note{{add a pair of parentheses}} expected-warning 2{{'typename' occurs outside of a template}}
   int five = f(5);
   
   using namespace N;