[clang] 1ae5310 - Changing some strange code into an assert; NFC

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 21 12:00:04 PDT 2022


Author: Aaron Ballman
Date: 2022-09-21T14:59:51-04:00
New Revision: 1ae5310ebbecadab52c1b7fc29596ac5b61795a3

URL: https://github.com/llvm/llvm-project/commit/1ae5310ebbecadab52c1b7fc29596ac5b61795a3
DIFF: https://github.com/llvm/llvm-project/commit/1ae5310ebbecadab52c1b7fc29596ac5b61795a3.diff

LOG: Changing some strange code into an assert; NFC

This code was added in b65b1f322bd88513586a4539d2b5f18aeb698f3f, but it
was not noticed that the [[fallthrough]] behavior was very wrong. In C
mode, we would set the ParenExprType to CompoundLiteral and then
promptly overwrite that information by falling through.

After some investigation, I convinced myself that it is not possible to
hit this code path in C, only in C++. I've switched it to be an
assertion; I don't expect to hit it, but if we do hit it, that will at
least give us a code example we can use to reason about the intent of
the original code.

Added: 
    

Modified: 
    clang/lib/Parse/ParseExpr.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 588f4cf6aa8c..77e8b9488a8c 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -943,8 +943,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
     ParenParseOption ParenExprType;
     switch (ParseKind) {
       case CastParseKind::UnaryExprOnly:
-        if (!getLangOpts().CPlusPlus)
-          ParenExprType = CompoundLiteral;
+        assert(getLangOpts().CPlusPlus && "not possible to get here in C");
         [[fallthrough]];
       case CastParseKind::AnyCastExpr:
         ParenExprType = ParenParseOption::CastExpr;


        


More information about the cfe-commits mailing list