Skip to content

Commit 99f02a8

Browse files
authored
[clang] Add tests for CWG issues about language linkage (#107019)
This patch covers Core issues about language linkage during declaration matching resolved in [P1787R6](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html), namely [CWG563](https://cplusplus.github.io/CWG/issues/563.html) and [CWG1818](https://cplusplus.github.io/CWG/issues/1818.html). [CWG563](https://cplusplus.github.io/CWG/issues/563.html) "Linkage specification for objects" ----------- [P1787R6](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html): > [CWG563](https://cplusplus.github.io/CWG/issues/563.html) is resolved by simplifications that follow its suggestions. Wording ([[dcl.link]/5](https://eel.is/c++draft/dcl.link#5)): > In a [linkage-specification](https://eel.is/c++draft/dcl.link#nt:linkage-specification), the specified language linkage applies to the function types of all function declarators and to all functions and variables whose names have external linkage[.](https://eel.is/c++draft/dcl.link#5.sentence-5) Now the wording clearly says that linkage-specification applies to variables with external linkage. [CWG1818](https://cplusplus.github.io/CWG/issues/1818.html) "Visibility and inherited language linkage" ------------ [P1787R6](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html): > [CWG386](http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#386), [CWG1839](http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1839), [CWG1818](http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1818), [CWG2058](http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2058), [CWG1900](http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1900), and Richard’s observation in [“are non-type names ignored in a class-head-name or enum-head-name?”](http://lists.isocpp.org/core/2017/01/1604.php) are resolved by describing the limited lookup that occurs for a declarator-id, including the changes in Richard’s [proposed resolution for CWG1839](http://wiki.edg.com/pub/Wg21cologne2019/CoreWorkingGroup/cwg1839.html) (which also resolves CWG1818 and what of CWG2058 was not resolved along with CWG2059) and rejecting the example from [CWG1477](http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1477). Wording ([[dcl.link]/6](https://eel.is/c++draft/dcl.link#6)): > A redeclaration of an entity without a linkage specification inherits the language linkage of the entity and (if applicable) its type[.](https://eel.is/c++draft/dcl.link#6.sentence-2). Answer to the question in the example is `extern "C"`, and not linkage mismatch. Further analysis of the example is provided as inline comments in the test itself. Note that https://eel.is/c++draft/dcl.link#7 does NOT apply in this example, as it's focused squarely at declarations that are already known to have C language linkage, and declarations of variables in the global scope.
1 parent c8763f0 commit 99f02a8

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

clang/test/CXX/drs/cwg1818.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %clang_cc1 -std=c++98 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
2+
// RUN: %clang_cc1 -std=c++11 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
3+
// RUN: %clang_cc1 -std=c++14 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
4+
// RUN: %clang_cc1 -std=c++17 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
5+
// RUN: %clang_cc1 -std=c++20 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
6+
// RUN: %clang_cc1 -std=c++23 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
7+
// RUN: %clang_cc1 -std=c++2c %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
8+
9+
// expected-no-diagnostics
10+
11+
namespace cwg1818 { // cwg1818: 3.4
12+
extern "C" void f() {
13+
// This declaration binds name 'g' in the scope of function 'f',
14+
// but its target scope corresponds to namespace 'cwg1818' (_N4988_.[dcl.meaning]/3.5).
15+
// Linkage specification of 'f' applies to 'g' per _N4988_.[dcl.link]/5.
16+
void g();
17+
}
18+
// Target scope of this declaration is naturally the one
19+
// that corresponds to namespace 'cwg1818',
20+
// which makes it declare the same entity
21+
// as the previous declaration per _N4988_.[basic.link]/8,
22+
// turning it into a redeclaration per _N4988_.[basic.def]/1.
23+
// Then _N4988_.[dcl.link]/6 applies, making it inherit
24+
// the (С) language linkage of the previous declaration.
25+
void g();
26+
} // namespace cwg1818
27+
28+
// Check that the former 'g' has C language linkage,
29+
// then that the latter 'g' is considered to be a redeclaration of it,
30+
// which would make the latter 'g' inherit C language linkage from the former 'g'.
31+
32+
// CHECK: LinkageSpecDecl [[LINKAGE_DECL:0x[0-9a-f]+]] {{.*}} C
33+
// CHECK: FunctionDecl [[FIRST_DECL:0x[0-9a-f]+]] parent [[LINKAGE_DECL]] {{.*}} g 'void ()'
34+
// CHECK: FunctionDecl {{.*}} prev [[FIRST_DECL]] {{.*}} g 'void ()'

clang/test/CXX/drs/cwg18xx.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ namespace cwg1815 { // cwg1815: no
222222
#endif
223223
}
224224

225+
// cwg1818 is in cwg1818.cpp
226+
225227
namespace cwg1820 { // cwg1820: 3.5
226228
typedef int A;
227229
typedef int cwg1820::A;

clang/test/CXX/drs/cwg563.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -std=c++98 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
2+
// RUN: %clang_cc1 -std=c++11 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
3+
// RUN: %clang_cc1 -std=c++14 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
4+
// RUN: %clang_cc1 -std=c++17 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
5+
// RUN: %clang_cc1 -std=c++20 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
6+
// RUN: %clang_cc1 -std=c++23 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
7+
// RUN: %clang_cc1 -std=c++2c %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s
8+
9+
// expected-no-diagnostics
10+
11+
namespace cwg563 { // cwg563: 3.3
12+
extern "C" int a;
13+
} // namespace cwg563
14+
15+
// CHECK: LinkageSpecDecl {{.*}} C
16+
// CHECK-NEXT: `-VarDecl {{.*}} a 'int'

clang/test/CXX/drs/cwg5xx.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ namespace cwg561 { // cwg561: yes
799799
}
800800

801801
// cwg562: na
802+
// cwg563 is in cwg563.cpp
802803

803804
namespace cwg564 { // cwg564: yes
804805
extern "C++" void f(int);

clang/www/cxx_dr_status.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,7 +3431,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
34313431
<td><a href="https://cplusplus.github.io/CWG/issues/563.html">563</a></td>
34323432
<td>CD6</td>
34333433
<td>Linkage specification for objects</td>
3434-
<td class="unknown" align="center">Unknown</td>
3434+
<td class="full" align="center">Clang 3.3</td>
34353435
</tr>
34363436
<tr id="564">
34373437
<td><a href="https://cplusplus.github.io/CWG/issues/564.html">564</a></td>
@@ -10735,7 +10735,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
1073510735
<td><a href="https://cplusplus.github.io/CWG/issues/1818.html">1818</a></td>
1073610736
<td>CD6</td>
1073710737
<td>Visibility and inherited language linkage</td>
10738-
<td class="unknown" align="center">Unknown</td>
10738+
<td class="full" align="center">Clang 3.4</td>
1073910739
</tr>
1074010740
<tr id="1819">
1074110741
<td><a href="https://cplusplus.github.io/CWG/issues/1819.html">1819</a></td>

0 commit comments

Comments
 (0)