]> granicus.if.org Git - clang/commitdiff
PR8023: Don't crash on invalid uses of __real__ on class types in C++.
authorEli Friedman <eli.friedman@gmail.com>
Sun, 5 Sep 2010 23:15:52 +0000 (23:15 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sun, 5 Sep 2010 23:15:52 +0000 (23:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113124 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaCXX/unary-real-imag.cpp [new file with mode: 0644]

index 815a962262855478ed351a49ad3d4d9b98b739c5..80b465230e14f538bc1392a8dd5ba5eaffddb1d5 100644 (file)
@@ -6796,7 +6796,7 @@ ExprResult Sema::BuildUnaryOp(Scope *S, SourceLocation OpLoc,
                               UnaryOperatorKind Opc,
                               Expr *Input) {
   if (getLangOptions().CPlusPlus && Input->getType()->isOverloadableType() &&
-      Opc != UO_Extension) {
+      UnaryOperator::getOverloadedOperator(Opc) != OO_None) {
     // Find all of the overloaded operators visible from this
     // point. We perform both an operator-name lookup from the local
     // scope and an argument-dependent lookup based on the types of
diff --git a/test/SemaCXX/unary-real-imag.cpp b/test/SemaCXX/unary-real-imag.cpp
new file mode 100644 (file)
index 0000000..91b63e3
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct A {};
+int i = __real__ A(); // expected-error {{invalid type 'A' to __real operator}}
+int j = __imag__ A(); // expected-error {{invalid type 'A' to __imag operator}}
+