From 0009ceee5934758fb972d4a253e3bf50a08efc3b Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Sun, 2 Aug 2015 00:03:09 +0200 Subject: [PATCH] Ticket #6793: Added basic unit test showing that basic integer shift length check is run even for templates. --- test/testtype.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/testtype.cpp b/test/testtype.cpp index 503156fbf..c9846fb7f 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -85,6 +85,15 @@ private: " someList << 300;\n" "}", &settings); ASSERT_EQUALS("", errout.str()); + + // Ticket #6793 + check("template int foo(int x) { return x << I; }\n" + "const int f = foo<31>(1);\n" + "const int g = foo<100>(1);\n" + "template int hoo(int x) { return x << 32; }\n" + "const int h = hoo<100>(1);", &settings); + ASSERT_EQUALS("[test.cpp:4]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\n" + "[test.cpp:1]: (error) Shifting 32-bit value by 100 bits is undefined behaviour\n", errout.str()); } void checkIntegerOverflow() {