This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 114a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-04-18


1817. Linkage specifications and nested scopes

Section: 9.11  [dcl.link]     Status: drafting     Submitter: Richard Smith     Date: 2013-12-04

According to 9.1 [dcl.pre] paragraph 2,

Unless otherwise stated, utterances in Clause 9 [dcl.dcl] about components in, of, or contained by a declaration or subcomponent thereof refer only to those components of the declaration that are not nested within scopes nested within the declaration.

This contradicts the intent of 9.11 [dcl.link] paragraph 4, which says,

In a linkage-specification, the specified language linkage applies to the function types of all function declarators, function names with external linkage, and variable names with external linkage declared within the linkage-specification.

Also, one of the comments in the example in paragraph 4 is inconsistent with the intent:

  extern "C" {
    static void f4(); // the name of the function f4 has
                      // internal linkage (not C language
                      // linkage) and the function's type
                      // has C language linkage.
  }

  extern "C" void f5() {
    extern void f4(); // OK: Name linkage (internal)
                      // and function type linkage (C
                      // language linkage) gotten from
                      // previous declaration.
  }

The language linkage for the block-scope declaration of f4 is presumably determined by the fact that it appears in a C-linkage function, not by the previous declaration.

Proposed resolution (February, 2014):

Change 9.11 [dcl.link] paragraph 4 as follows:

Linkage specifications nest. When linkage specifications nest, the innermost one determines the language linkage. A linkage specification does not establish a scope. A linkage-specification shall occur only in namespace scope (6.4 [basic.scope]). In a linkage-specification, the specified language linkage applies to the function types of all function declarators, function names with external linkage, and variable names with external linkage declared within the linkage-specification, including those appearing in scopes nested inside the linkage specification and not inside a nested linkage-specification. [Example:

...

  extern "C" {
    static void f4(); // the name of the function f4 has
                      // internal linkage (not C language
                      // linkage) and the function's type
                      // has C language linkage.
  }

  extern "C" void f5() {
    extern void f4(); // OK: Name linkage (internal)
                      // and function type linkage (C
                      // language linkage) gotten from
                      // previous declaration.; function type
                      // linkage (C language
                      // linkage) gotten
                      // from linkage specification
  }

Additional note, November, 2014:

The issue has been returned to "drafting" status to clarify the circumstances under which a preceding declaration supplies the language linkage for a declaration (for example, not when the declaration uses a typedef, which carries the language linkage, but only when the declaration uses a function declarator).