Title
Visibility and inherited language linkage
Status
cd6
Section
9.11 [dcl.link]
Submitter
Richard Smith

Created on 2013-12-04.00:00:00 last changed 20 months ago

Messages

Date: 2020-11-15.00:00:00

[Accepted at the November, 2020 meeting as part of paper P1787R6 and moved to DR at the February, 2021 meeting.]

Does the language linkage of a block-scope declaration determine the language linkage of a subsequent declaration of the same name in a different scope? For example,

   extern "C" void f() {
     void g();    // Implicitly extern "C"
   }
   void g() { }   // Also extern "C" or linkage mismatch?

In other contexts, inheritance of linkage requires that the earlier declaration be visible, as in 6.6 [basic.link] paragraph 6:

The name of a function declared in block scope and the name of a variable declared by a block scope extern declaration have linkage. If there is a visible declaration of an entity with linkage having the same name and type, ignoring entities declared outside the innermost enclosing namespace scope, the block scope declaration declares that same entity and receives the linkage of the previous declaration.

The specification for language linkage in 9.11 [dcl.link] paragraph 5, however, makes no mention of visibility:

A function can be declared without a linkage specification after an explicit linkage specification has been seen; the linkage explicitly specified in the earlier declaration is not affected by such a function declaration.
History
Date User Action Args
2022-08-19 07:54:33adminsetstatus: drwp -> cd6
2021-02-24 00:00:00adminsetstatus: accepted -> drwp
2020-12-15 00:00:00adminsetstatus: open -> accepted
2013-12-04 00:00:00admincreate