C++
- voluntas
 - @ignis_fatuus
 - ブン
 - @Linda_pp
 - 清楚なC++メイドBOT
 - @tzik_tack
 - 長谷川一輝
 - wraith13
 - @jj1bdx
 - @cpp_akira
 - 安藤敏彦
 - @srz_zumix
 - Siv3D
 - @okdshin
 - @hnokx
 - @ishidakei
 - @take_cheeze
 - TAKEI Yuya
 - @mumumu
 - I (@wx257osn2)
 - Tommy6
 - わたやん
 - @KorekaraSEDB
 - @kariya_mitsuru
 - @ciniml
 - @beam2d
 - @grafi_tt
 - @nekketsuuu
 - LouiS0616
 - @volanja
 - 大鎌広
 - むてら
 - ガチKGB
 - 三重野賢人
 
x
19
1
template<typename T>2
class Test3
{4
public:5
    static constexpr int sdm = T(nullptr);6
    static int f(void){static_assert(sizeof(T)==0);}7
    int g(void){static_assert(sizeof(T)==0);}8
};9
10
int main()11
{12
   Test<int> intTest;  //**It compiles!  It's a declaration instead of a definition! Why?**13
14
   //the compiler would complain if adding one of these line.15
   intTest.f();  16
   intTest.sdm;17
   intTest.g();18
}19
$ g++ prog.cc -Wall -Wextra -std=c++17 -pedantic 
Start
prog.cc: In static member function 'static int Test<T>::f()':
prog.cc:6:52: warning: no return statement in function returning non-void [-Wreturn-type]
    6 |     static int f(void){static_assert(sizeof(T)==0);}
      |                                                    ^
prog.cc: In member function 'int Test<T>::g()':
prog.cc:7:45: warning: no return statement in function returning non-void [-Wreturn-type]
    7 |     int g(void){static_assert(sizeof(T)==0);}
      |                                             ^
prog.cc: In instantiation of 'constexpr const int Test<int>::sdm':
prog.cc:16:12:   required from here
prog.cc:5:32: error: cast from 'std::nullptr_t' to 'int' loses precision [-fpermissive]
    5 |     static constexpr int sdm = T(nullptr);
      |                                ^~~~~~~~~~
prog.cc: In function 'int main()':
prog.cc:16:15: warning: statement has no effect [-Wunused-value]
   16 |    intTest.sdm;
      |               ^
prog.cc: In instantiation of 'static int Test<T>::f() [with T = int]':
prog.cc:15:14:   required from here
prog.cc:6:47: error: static assertion failed
    6 |     static int f(void){static_assert(sizeof(T)==0);}
      |                                      ~~~~~~~~~^~~
prog.cc: In instantiation of 'int Test<T>::g() [with T = int]':
prog.cc:17:14:   required from here
prog.cc:7:40: error: static assertion failed
    7 |     int g(void){static_assert(sizeof(T)==0);}
      |                               ~~~~~~~~~^~~
1
Finish