Ticket #6793: Added basic unit test showing that basic integer shift length check is run even for templates.

This commit is contained in:
Simon Martin 2015-08-02 00:03:09 +02:00
parent 965a034afd
commit 0009ceee59
1 changed files with 9 additions and 0 deletions

View File

@ -85,6 +85,15 @@ private:
" someList << 300;\n" " someList << 300;\n"
"}", &settings); "}", &settings);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// Ticket #6793
check("template<int I> int foo(int x) { return x << I; }\n"
"const int f = foo<31>(1);\n"
"const int g = foo<100>(1);\n"
"template<int I> 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() { void checkIntegerOverflow() {