This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe53b9f733a7c: Print source location in the error message 
when parens are missing around… (authored by shivanshu3, committed by rsmith).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91129/new/

https://reviews.llvm.org/D91129

Files:
  clang/lib/Parse/ParseExpr.cpp
  clang/test/Parser/sizeof-missing-parens.c


Index: clang/test/Parser/sizeof-missing-parens.c
===================================================================
--- /dev/null
+++ clang/test/Parser/sizeof-missing-parens.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void Foo(int);
+
+#define Bar(x) Foo(x)
+
+void Baz() {
+  Foo(sizeof int); // expected-error {{expected parentheses around type name 
in sizeof expression}}
+  Bar(sizeof int); // expected-error {{expected parentheses around type name 
in sizeof expression}}
+}
Index: clang/lib/Parse/ParseExpr.cpp
===================================================================
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -2266,10 +2266,15 @@
 
         SourceLocation LParenLoc = PP.getLocForEndOfToken(OpTok.getLocation());
         SourceLocation RParenLoc = PP.getLocForEndOfToken(PrevTokLocation);
-        Diag(LParenLoc, diag::err_expected_parentheses_around_typename)
-          << OpTok.getName()
-          << FixItHint::CreateInsertion(LParenLoc, "(")
-          << FixItHint::CreateInsertion(RParenLoc, ")");
+        if (LParenLoc.isInvalid() || RParenLoc.isInvalid()) {
+          Diag(OpTok.getLocation(),
+               diag::err_expected_parentheses_around_typename)
+              << OpTok.getName();
+        } else {
+          Diag(LParenLoc, diag::err_expected_parentheses_around_typename)
+              << OpTok.getName() << FixItHint::CreateInsertion(LParenLoc, "(")
+              << FixItHint::CreateInsertion(RParenLoc, ")");
+        }
         isCastExpr = true;
         return ExprEmpty();
       }


Index: clang/test/Parser/sizeof-missing-parens.c
===================================================================
--- /dev/null
+++ clang/test/Parser/sizeof-missing-parens.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void Foo(int);
+
+#define Bar(x) Foo(x)
+
+void Baz() {
+  Foo(sizeof int); // expected-error {{expected parentheses around type name in sizeof expression}}
+  Bar(sizeof int); // expected-error {{expected parentheses around type name in sizeof expression}}
+}
Index: clang/lib/Parse/ParseExpr.cpp
===================================================================
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -2266,10 +2266,15 @@
 
         SourceLocation LParenLoc = PP.getLocForEndOfToken(OpTok.getLocation());
         SourceLocation RParenLoc = PP.getLocForEndOfToken(PrevTokLocation);
-        Diag(LParenLoc, diag::err_expected_parentheses_around_typename)
-          << OpTok.getName()
-          << FixItHint::CreateInsertion(LParenLoc, "(")
-          << FixItHint::CreateInsertion(RParenLoc, ")");
+        if (LParenLoc.isInvalid() || RParenLoc.isInvalid()) {
+          Diag(OpTok.getLocation(),
+               diag::err_expected_parentheses_around_typename)
+              << OpTok.getName();
+        } else {
+          Diag(LParenLoc, diag::err_expected_parentheses_around_typename)
+              << OpTok.getName() << FixItHint::CreateInsertion(LParenLoc, "(")
+              << FixItHint::CreateInsertion(RParenLoc, ")");
+        }
         isCastExpr = true;
         return ExprEmpty();
       }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D91129: P... Shivanshu Goyal via Phabricator via cfe-commits
    • [PATCH] D911... Shivanshu Goyal via Phabricator via cfe-commits
    • [PATCH] D911... Richard Smith - zygoloid via Phabricator via cfe-commits
    • [PATCH] D911... Shivanshu Goyal via Phabricator via cfe-commits
    • [PATCH] D911... Shivanshu Goyal via Phabricator via cfe-commits
    • [PATCH] D911... Richard Smith - zygoloid via Phabricator via cfe-commits

Reply via email to