Search code examples
c++language-lawyerc++14function-declaration

The term `function declaration` is defined in §7/9 (N4140), but it isn't defined as a grammar production. Why?


In §7/9 you'll find the definition of a function declaration:

If the decl-specifier-seq contains no typedef specifier, the declaration is called a function declaration if the type associated with the name is a function type (8.3.5) and an object declaration otherwise.

In §7/1 you can find the definition of the grammar-production declaration, but there is no function-declaration nominated in there, as part of this definition. In other words, how would one classify function declaration in the C++ grammar?


Solution

  • Since that paragraph talks about init-declarators, I take it to apply to a simple-declaration in which there is an init-declarator-list. You can see that this is not entirely correct

    // clearly, this is not the declaration of an object, so it should
    // not be called an "object declaration", but 7p9 does say so
    int &a = x;
    
    struct A {
       // AFAICS 7p9 should also apply here, but there is no init-declarator
       // here, but a member-declarator. 9.2 also doesn't delegate to 7p9.
       typedef int a;
    };
    

    A consequence is that the following also contains a function declaration, but that declaration declares not a function.

    template<typename T> void f();
    

    In summary, I think there is some clarification on this text desired in the spec.