]> granicus.if.org Git - clang/commitdiff
Handle value dependent LHS as well as RHS. Test both of these, they
authorChandler Carruth <chandlerc@gmail.com>
Thu, 24 Feb 2011 00:03:53 +0000 (00:03 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Thu, 24 Feb 2011 00:03:53 +0000 (00:03 +0000)
don't seem to have been covered by our tests previously.

This should fix bootstrap failure.

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

lib/Sema/SemaExpr.cpp
test/SemaCXX/shift.cpp [new file with mode: 0644]

index 076ffeb26878303ec4c2cc1dfc36867062cda0ce..0a7d22dd64b5b4e8ccfda0312f4746abba23d39d 100644 (file)
@@ -6652,7 +6652,7 @@ static void DiagnoseBadShiftValues(Sema& S, Expr *&lex, Expr *&rex,
   // integers have defined behavior modulo one more than the maximum value
   // representable in the result type, so never warn for those.
   llvm::APSInt Left;
-  if (!lex->isIntegerConstantExpr(Left, S.Context) ||
+  if (lex->isValueDependent() || !lex->isIntegerConstantExpr(Left, S.Context) ||
       LHSTy->hasUnsignedIntegerRepresentation())
     return;
   llvm::APInt ResultBits =
diff --git a/test/SemaCXX/shift.cpp b/test/SemaCXX/shift.cpp
new file mode 100644 (file)
index 0000000..c5e5012
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -Wall -Wshift-sign-overflow -ffreestanding -fsyntax-only -verify %s
+
+#include <limits.h>
+
+#define WORD_BIT (sizeof(int) * CHAR_BIT)
+
+template <int N> void f() {
+  (void)(N << 30); // expected-warning {{the promoted type of the shift expression is 'int'}}
+  (void)(30 << N); // expected-warning {{the promoted type of the shift expression is 'int'}}
+}
+
+void test() {
+  f<30>(); // expected-note {{instantiation}}
+}