[LLVMbugs] [Bug 14043] New: An overflow in a non-type template parameter is not detected
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Mon Oct 8 14:55:19 PDT 2012
http://llvm.org/bugs/show_bug.cgi?id=14043
Bug #: 14043
Summary: An overflow in a non-type template parameter is not
detected
Product: clang
Version: 3.1
Platform: PC
OS/Version: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Frontend
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: tmmikolajczyk at gmail.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Created attachment 9321
--> http://llvm.org/bugs/attachment.cgi?id=9321
Application calculating Fibonacci seq at compile time
Consider this trivial Fibonacci sequence calculation at compile time:
template<int v>
struct fib
{
static_assert(v > 1, "fib<0> and fib<1> are special");
enum { value = fib<v-1>::value + fib<v-2>::value };
};
template<>
struct fib<0> { enum { value = 0 }; };
template<>
struct fib<1> { enum { value = 1 }; };
std::cout << fib<0>::value << std::endl;
std::cout << fib<1>::value << std::endl;
std::cout << fib<2>::value << std::endl;
std::cout << fib<3>::value << std::endl;
std::cout << fib<4>::value << std::endl;
std::cout << fib<5>::value << std::endl;
std::cout << fib<45>::value << std::endl; // 1134903170
std::cout << fib<46>::value << std::endl; // 1836311903
std::cout << fib<47>::value << std::endl; // integer overflow
gcc (4.7.1) complains when tries to instantiate the fib<47>:
~$ g++ -std=c++11 fib.cpp
fib.cpp: In instantiation of `struct fib<47>':
fib.cpp:30:25: required from here
fib.cpp:7:10: warning: integer overflow in expression [-Woverflow]
fib.cpp:7:10: error: overflow in constant expression [-fpermissive]
fib.cpp:7:10: error: enumerator value for `value' is not an integer constant
However clang keeps going silently:
~$ clang++ -std=c++11 fib.cpp
~$ ./a.out
0
1
1
2
3
5
8
13
21
34
1134903170
1836311903
-1323752223
~$
Would be good to have the overflow detected as well. The fib.cpp file from the
attachment contains the whole app.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list