2017-06-05 45 views
5

Otrzymuję "błąd: specyfikacje wyjątków nie są dozwolone poza pojedynczym poziomem pośrednim" z następującym kodem. Proszę wskazać mi książkę/specyfikację, która mówi, że nie jest dozwolona. Chcę mieć pewność, że jest to naprawdę wymagane przez język lub po prostu błąd specyficzny dla kompilatora. Jeśli wynika to ze specyfikacji językowej, co motywuje tę zasadę? Używam clang 3.8.0.C++, błąd wyjątku wskaźnika funkcji

int main() 
    { 
     void (**fp)() throw() ; 
    } 
+0

"Proszę wskazać mi książkę/specyfikację, która mówi, że nie jest dozwolona." - standardowy? –

+0

@EdgarRokyan Powinienem był użyć "standard" zamiast "spec". Każdy, możesz edytować pytanie. – qqqqq

Odpowiedz

6

Mówiłeś:

Please point me to a reference book /spec that says that it is not allowed. I want to be sure that it is really required by the language or just compiler specific error.

Z

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

próbujesz określić wyjątku specyfikacją w deklaracji wskaźnika do wskaźnika funkcji. To nie jest dozwolone przez standard. Wyjątek-specyfikacja jest dozwolony tylko dla ograniczonego zestawu deklaracji.

Od https://timsong-cpp.github.io/cppwp/n3337/except.spec#2 kopalni (nacisk):

An exception-specification shall appear only on a function declarator for a function type, pointer to function type, reference to function type, or pointer to member function type that is the top-level type of a declaration or definition, or on such a type appearing as a parameter or return type in a function declarator. An exception-specification shall 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 example ] A type denoted in an exception-specification shall not denote an incomplete type. A type denoted in an exception-specification shall not denote a pointer or reference to an incomplete type, other than void* , const void* , volatile void* , or const volatile void* . A type cvT , “array of T ”, or “function returning T ” denoted in an exception-specification is adjusted to type T , “pointer to T ”, or “pointer to function returning T ”, respectively.


Pytałeś:

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

Nie mam odpowiedzi na to pytanie.