[clang] 38d3e75 - [clang] Use the location of the void parameters when complaining that only a single void parameter should be present.

Bruno Ricci via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 31 12:37:11 PDT 2020


Author: Jaydeep Chauhan
Date: 2020-07-31T20:36:58+01:00
New Revision: 38d3e7533279fd4bfefcd88eac7d3b64f804c53a

URL: https://github.com/llvm/llvm-project/commit/38d3e7533279fd4bfefcd88eac7d3b64f804c53a
DIFF: https://github.com/llvm/llvm-project/commit/38d3e7533279fd4bfefcd88eac7d3b64f804c53a.diff

LOG: [clang] Use the location of the void parameters when complaining that only a single void parameter should be present.

Fixes PR46417.

Differential Revision: https://reviews.llvm.org/D84678

Reviewed By: aaron.ballman

Added: 
    clang/test/SemaCXX/void-argument.cpp

Modified: 
    clang/lib/Sema/SemaType.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index abf1d6450036..ff5223c0795e 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5114,7 +5114,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
             // is an incomplete type (C99 6.2.5p19) and function decls cannot
             // have parameters of incomplete type.
             if (FTI.NumParams != 1 || FTI.isVariadic) {
-              S.Diag(DeclType.Loc, diag::err_void_only_param);
+              S.Diag(FTI.Params[i].IdentLoc, diag::err_void_only_param);
               ParamTy = Context.IntTy;
               Param->setType(ParamTy);
             } else if (FTI.Params[i].Ident) {

diff  --git a/clang/test/SemaCXX/void-argument.cpp b/clang/test/SemaCXX/void-argument.cpp
new file mode 100644
index 000000000000..8354347f5559
--- /dev/null
+++ b/clang/test/SemaCXX/void-argument.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void fun(
+    void a, // expected-error{{'void' must be the first and only parameter if specified}}
+    double b,
+    int c,
+    void d, // expected-error{{'void' must be the first and only parameter if specified}}
+    int e,
+    void f) // expected-error{{'void' must be the first and only parameter if specified}}
+{}
+
+void foo(
+    int a,
+    void, // expected-error{{'void' must be the first and only parameter if specified}}
+    int b);
+
+void bar(
+    void, // expected-error{{'void' must be the first and only parameter if specified}}
+    ...);
+
+struct S {
+  S(
+      void,  // expected-error{{'void' must be the first and only parameter if specified}}
+      void); // expected-error{{'void' must be the first and only parameter if specified}}
+};


        


More information about the cfe-commits mailing list