]> granicus.if.org Git - clang/commitdiff
Change Expr::isLvalue() to properly deal with ImplicitCastExpr's.
authorSteve Naroff <snaroff@apple.com>
Sat, 25 Aug 2007 14:37:06 +0000 (14:37 +0000)
committerSteve Naroff <snaroff@apple.com>
Sat, 25 Aug 2007 14:37:06 +0000 (14:37 +0000)
This fixes the following bug...

t.c:1:31: error: expression is not assignable
short x; void foo(char c) { x += c; }

This case, among others are now captured in implicit-casts.c.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41402 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp
test/Parser/implicit-casts.c [new file with mode: 0644]

index 535e1ef786f1938ffd70036a35d2467c661600ba..5167d4e109b3fef6f709f87e6f2234b5221cdfef 100644 (file)
@@ -302,6 +302,8 @@ Expr::isLvalueResult Expr::isLvalue() const {
     if (cast<OCUVectorElementExpr>(this)->containsDuplicateElements())
       return LV_DuplicateVectorComponents;
     return LV_Valid;
+  case ImplicitCastExprClass: // A side-effect of our implementation.
+    return cast<ImplicitCastExpr>(this)->getSubExpr()->isLvalue();
   default:
     break;
   }
diff --git a/test/Parser/implicit-casts.c b/test/Parser/implicit-casts.c
new file mode 100644 (file)
index 0000000..4ba56e4
--- /dev/null
@@ -0,0 +1,20 @@
+// RUN: clang -parse-ast-check %s
+_Complex double X;
+void test1(int c) {
+  X = 5;
+}
+void test2() {
+  int i;
+  double d = i;
+  double _Complex a = 5;
+
+  test1(a);
+  a = 5;
+  d = i;
+}
+int test3() {
+  int a[2];
+  a[0] = test3; // expected-warning{{incompatible types assigning 'int (void)' to 'int'}}
+}
+short x; void test4(char c) { x += c; }
+int y; void test5(char c) { y += c; }