C ++, function pointer exception error

I get an “error: exception specifications are not allowed beyond one level of indirection” with the following code. Please provide me with a guide / specification that states that it is prohibited. I want to be sure that this is really required by the language or just a compiler error. If it is from the language specification, what motivates this rule? I am using clang 3.8.0.

int main() { void (**fp)() throw() ; } 
+5
source share
1 answer

You said:

Please provide me with a guide / specification that states that it is prohibited. I want to be sure that this is really required by the language or just a compiler error.

WITH

 void (**fp)() throw() ; 

You are trying to specify an exception specification in a pointer declaration to a function pointer. This is prohibited by standard. Exclusion specifications are allowed only for a limited set of ads.

From https://timsong-cpp.imtqy.com/cppwp/n3337/except.spec#2 (my attention):

An exception specification should only appear in a function declaration for a function type , a pointer to a function type , a reference to a function type , or a pointer to a member function type that is a top-level declaration type or definition, or that type that appears as a parameter or return type values ​​in function declaration . An exception specification should not appear in a typedef declaration or alias declaration. [Example:

  void f() throw(int); // OK void (*fp)() throw (int); // OK void g(void pfa() throw(int)); // OK typedef int (*pf)() throw(int); // ill-formed 

- end of example] The type indicated in the exception specification should not indicate an incomplete type. The type indicated in the exception specification must not indicate a pointer or reference to an incomplete type except void* , const void* , volatile void* or const volatile void* . Type cv T , "array of T " or "function return T " indicated in the exception specification is configured to type T , "pointer to T " or "pointer to function returning T ", respectively.


You asked:

If it is from the language specification, what motivates this rule?

I have no answer to this question.

+6
source

Source: https://habr.com/ru/post/1268566/


All Articles