2017-06-05 5 views
5

Ich bekomme "Fehler: Ausnahmespezifikationen sind nicht über eine einzige Ebene der Indirektion" mit dem folgenden Code erlaubt. Bitte weisen Sie mich auf ein Nachschlagewerk hin, das besagt, dass es nicht erlaubt ist. Ich möchte sicher sein, dass es wirklich von der Sprache oder nur compilerspezifischen Fehler benötigt wird. Wenn es von der Sprachspezifikation ist, was motiviert diese Regel? Ich benutze clang 3.8.0.C++, Funktion Zeiger Ausnahme Fehler

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

"Bitte verweisen Sie mich auf ein Nachschlagewerk, das besagt, dass es nicht erlaubt ist." - Standard? –

+0

@ EdgarRokyan Ich hätte "Standard" anstatt "Spec" verwenden sollen. Jeder, bitte zögern Sie nicht, die Frage zu bearbeiten. – qqqqq

Antwort

6

Sie sagte:

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.

Mit

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

Sie eine Ausnahme-Spezifikation in der Deklaration eines Zeigers auf einen Funktionszeiger angeben wollen. Das ist vom Standard nicht erlaubt. Ausnahme-Spezifikation ist nur für eine begrenzte Anzahl von Deklarationen zulässig.

Von https://timsong-cpp.github.io/cppwp/n3337/except.spec#2 (Hervorhebung von mir):

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.


Sie gefragt:

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

Ich habe keine Antwort darauf.