Merge pull request #631 from simartin/ticket_6793

Ticket #6793: Added basic unit test showing that basic integer shift length check is run even for templates.
This commit is contained in:
amai2012 2015-08-02 08:51:04 +02:00
commit 0ca088d0cf
1 changed files with 9 additions and 0 deletions

View File

@ -85,6 +85,15 @@ private:
" someList << 300;\n"
"}", &settings);
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() {