Objective-C properties aren't handled on purpose as they require
different approach.
rdar://problem/35539384
Differential D42938
[Sema] Emit -Winteger-overflow for arguments in function calls, ObjC messages. Authored by vsapsai on Feb 5 2018, 4:38 PM.
Details
Objective-C properties aren't handled on purpose as they require rdar://problem/35539384
Diff Detail
Event TimelineComment Actions Ping. It would be helpful to know how reasonable is the idea to handle more expression types in Sema::CheckForIntOverflow. Comment Actions Maybe a stupid idea but in case it makes sense to add these expression types could we also add integer template arguments? Comment Actions The idea isn't stupid but I think it is already handled. For template<int N> void f() {} template<int N = 1000000 * 10240> void g() {} void foo() { f<1000000 * 10240>(); g(); } I got errors template-args.cpp:2:18: error: non-type template argument is not a constant expression
template<int N = 1000000 * 10240> void g() {}
^~~~~~~~~~~~~~~
template-args.cpp:2:26: note: value 10240000000 is outside the range of representable values of type 'int'
template<int N = 1000000 * 10240> void g() {}
^
template-args.cpp:5:5: error: no matching function for call to 'f'
f<1000000 * 10240>();
^~~~~~~~~~~~~~~~~~
template-args.cpp:1:22: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'N'
template<int N> void f() {}
^
template-args.cpp:6:5: error: no matching function for call to 'g'
g();
^
template-args.cpp:2:40: note: candidate template ignored: couldn't infer template argument 'N'
template<int N = 1000000 * 10240> void g() {}
^
3 errors generated.Do you have some other template arguments usage in mind? Comment Actions Sorry, my bad, I tried just older clang version which didn't produce any error. With reasonably up to date clang I get these: > cat tmpl_overflow.hpp template<int N> struct foo { short a; };
template<> struct foo<1000000000000000000 * 10240> { bool a; };
int main() {
foo<1000000000000000000 * 10240> a;
}> ~/src/oss/llvm@master/build/bin/clang++ tmpl_overflow.hpp
tmpl_overflow.hpp:3:23: error: non-type template argument is not a constant expression
template<> struct foo<1000000000000000000 * 10240> { bool a; };
^~~~~~~~~~~~~~~~~~~~~~~~~~~
tmpl_overflow.hpp:3:43: note: value 10240000000000000000000 is outside the range of representable values of type 'long'
template<> struct foo<1000000000000000000 * 10240> { bool a; };
^
tmpl_overflow.hpp:6:9: error: non-type template argument is not a constant expression
foo<1000000000000000000 * 10240> a;
^~~~~~~~~~~~~~~~~~~~~~~~~~~
tmpl_overflow.hpp:6:29: note: value 10240000000000000000000 is outside the range of representable values of type 'long'
foo<1000000000000000000 * 10240> a;
^
2 errors generated.I am not actually sure those error messages are correct (not constant? type 'long'?) but I am not sure it's still within the scope of your patch either. What is interesting is that by using lower value (which is still to big for short) I probably hit different diagnostic check and get different error: > cat tmpl_overflow.hpp template<int N> struct foo { short a; };
template<> struct foo<100000000000000 * 10240> { bool a; };
int main() {
foo<100000000000000 * 10240> a;
} jankorous @ jans-imac /Users/jankorous/tmp
> ~/src/oss/llvm@master/build/bin/clang++ tmpl_overflow.hpp
tmpl_overflow.hpp:3:23: error: non-type template argument evaluates to 1024000000000000000, which cannot be narrowed to type 'int' [-Wc++11-narrowing]
template<> struct foo<100000000000000 * 10240> { bool a; };
^
tmpl_overflow.hpp:6:9: error: non-type template argument evaluates to 1024000000000000000, which cannot be narrowed to type 'int' [-Wc++11-narrowing]
foo<100000000000000 * 10240> a;
^
2 errors generated. |