jkorous-apple added a comment.

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.


https://reviews.llvm.org/D42938



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to