使用下面的代碼,我得到「錯誤:超出單一間接級別的異常規範」。請給我一個參考書/規範,說它不被允許。我想確定它確實是語言所必需的,或者只是編譯器特定的錯誤。如果從語言規範來看,這個規則是什麼動力?我使用的是鏗鏘3.8.0。C++,函數指針異常錯誤
int main()
{
void (**fp)() throw() ;
}
使用下面的代碼,我得到「錯誤:超出單一間接級別的異常規範」。請給我一個參考書/規範,說它不被允許。我想確定它確實是語言所必需的,或者只是編譯器特定的錯誤。如果從語言規範來看,這個規則是什麼動力?我使用的是鏗鏘3.8.0。C++,函數指針異常錯誤
int main()
{
void (**fp)() throw() ;
}
你說:
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.
隨着
void (**fp)() throw() ;
你想在一個指向函數指針的聲明指定一個異常規範。這是標準所不允許的。 例外規範僅適用於有限的一組聲明。
從https://timsong-cpp.github.io/cppwp/n3337/except.spec#2(重點煤礦):
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*
, orconst volatile void*
. A type cvT
, 「array ofT
」, or 「function returningT
」 denoted in an exception-specification is adjusted to typeT
, 「pointer toT
」, or 「pointer to function returningT
」, respectively.
你問:
If it is from language specification, what motivates this rule?
我沒有一個答案。
「請給我一個參考書/規範,說它不被允許。」 - 標準? –
@EdgarRokyan我應該用「標準」代替「規範」。任何人,請隨時編輯問題。 – qqqqq