Jac1494 created this revision.
Jac1494 added a reviewer: rsmith.
Jac1494 added a project: clang.
Herald added a subscriber: cfe-commits.

This patch fixes  false line number in a function definition with "void" 
parameter.
For more details PR46417.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84678

Files:
  clang/lib/Sema/SemaType.cpp
  clang/test/Sema/void-argument.cpp


Index: clang/test/Sema/void-argument.cpp
===================================================================
--- /dev/null
+++ clang/test/Sema/void-argument.cpp
@@ -0,0 +1,15 @@
+// RUN: not %clang_cc1 %s 2>&1 | FileCheck %s
+
+// CHECK: void-argument.cpp:9:6: error: 'void' must be the first and only 
parameter if specified
+// CHECK: void-argument.cpp:12:7: error: 'void' must be the first and only 
parameter if specified
+// CHECK: void-argument.cpp:14:6: error: 'void' must be the first and only 
parameter if specified
+// CHECK: 3 errors generated.
+
+void foo (
+void a,
+double b,
+int c,
+void  d,
+int e,
+void f)
+{}
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5109,7 +5109,7 @@
             // 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) {


Index: clang/test/Sema/void-argument.cpp
===================================================================
--- /dev/null
+++ clang/test/Sema/void-argument.cpp
@@ -0,0 +1,15 @@
+// RUN: not %clang_cc1 %s 2>&1 | FileCheck %s
+
+// CHECK: void-argument.cpp:9:6: error: 'void' must be the first and only parameter if specified
+// CHECK: void-argument.cpp:12:7: error: 'void' must be the first and only parameter if specified
+// CHECK: void-argument.cpp:14:6: error: 'void' must be the first and only parameter if specified
+// CHECK: 3 errors generated.
+
+void foo (
+void a,
+double b,
+int c,
+void  d,
+int e,
+void f)
+{}
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5109,7 +5109,7 @@
             // 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) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to