is it correct in C++: exception in typedef

hi, CFE list,

I wonder if C++ allows to declare exception spec in typdef.

eg.
typedef int name() throw(int) ;

I tested t.cpp using g++/clang, they all forbid this behavior.

clang gives me quite clear answer.

t.cpp:4:20: error: exception specifications are not allowed in typedefs
typedef int name() throw(int) ;
^
t.cpp:5:24: error: exception specifications are not allowed in typedefs
typedef int (*pname)() throw(int) ;
^
t.cpp:6:24: error: exception specifications are not allowed in typedefs
typedef int (&rname)() throw(int) ;
^
3 errors generated.

t.cpp is actually from microsoft’s AMP testsuite. I believe VC++ accepts it (sorry, I didn’t verify using vc++, because I can’t access windows by now).

According to my google result, N4533 and P0012R1 try to remove this restriction, am I right?
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0012r1.html

thanks,
–lx

t.cpp (200 Bytes)

hi, CFE list,

I wonder if C++ allows to declare exception spec in typdef.

No current C++ standard allows this. C++17 will (and more generally,
exception specifications become a first-class part of the type system in
C++17), but this feature is not yet implemented (see
http://clang.llvm.org/cxx_status.html#cxx17).

eg.
typedef int name() throw(int) ;

I tested t.cpp using g++/clang, they all forbid this behavior.

clang gives me quite clear answer.
t.cpp:4:20: error: exception specifications are not allowed in typedefs
typedef int name() throw(int) ;
                   ^
t.cpp:5:24: error: exception specifications are not allowed in typedefs
typedef int (*pname)() throw(int) ;
                       ^
t.cpp:6:24: error: exception specifications are not allowed in typedefs
typedef int (&rname)() throw(int) ;
                       ^
3 errors generated.

t.cpp is actually from microsoft's AMP testsuite. I believe VC++ accepts
it (sorry, I didn't verify using vc++, because I can't access windows by
now).

According to my google result, N4533 and P0012R1 try to remove this
restriction, am I right?
P0012R1: Make exception-specifications be part of the type system, version 5

Correct. They also make 'throw(int)' a deprecated synonym of
'noexcept(false)'. I suspect MSVC just doesn't implement the C++98 rule,
rather than already implementing the P0012 rule...

Richard,

thank you for the explanation.

thanks,
–lx