Skip to content

Commit f1c9ef3

Browse files
committed
Add test coverage for WG14 N2322
The changes in this paper add a new recommended practice. I had originally marked Clang as supporting this paper because we're not obligated to follow a recommended practice. However, in retrospect, it seems more useful to document whether we implement the recommendation or not. This adds a test for those changes.
1 parent 340cf21 commit f1c9ef3

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

clang/test/C/C2x/n2322.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// RUN: %clang_cc1 -std=c2x -ast-dump %s | FileCheck %s
2+
3+
/* WG14 N2322: partial
4+
* Preprocessor line numbers unspecified
5+
*/
6+
void n2322() {
7+
// The line number associated with a pp-token should be the line number of
8+
// the first character of the pp-token.
9+
"this string literal \
10+
spans multiple lines \
11+
before terminating";
12+
// CHECK: ImplicitCastExpr {{.*}} <line:9
13+
// CHECK-NEXT: StringLiteral {{.*}} <col:3>
14+
15+
// The line number associated with a pp-directive should be the line number
16+
// of the line with the first # token.
17+
// Possible FIXME: The AST node should be on line 1002 if we take the line
18+
// number to be associated with the first # token. However, this relies on an
19+
// interpretation of the standard definition of "presumed line" to be before
20+
// line splices are removed. The standard leaves this unspecified, so this
21+
// may not represent an actual issue.
22+
#\
23+
line\
24+
1000
25+
"string literal";
26+
// CHECK: ImplicitCastExpr {{.*}} <line:1000
27+
// CHECK: StringLiteral {{.*}} <col:3>
28+
29+
// The line number associated with a macro invocation should be the line
30+
// number of the first character of the macro name in the invocation.
31+
//
32+
// Reset the line number to make it easier to understand the next test.
33+
// FIXME: The line number should be 2005 (first letter of the macro name) and
34+
// not 2007 (closing parenthesis of the macro invocation).
35+
#line 2000
36+
#define F( \
37+
) \
38+
_\
39+
_LINE__
40+
41+
_Static_assert(F(\
42+
\
43+
) == 2007);
44+
45+
// Reset the line number again for ease.
46+
#line 2000
47+
_Static_assert(2001 == \
48+
__LI\
49+
NE__\
50+
);
51+
}

clang/www/c_status.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,15 @@ <h2 id="c2x">C2x implementation status</h2>
696696
<tr>
697697
<td>Preprocessor line numbers unspecified</td>
698698
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2322.htm">N2322</a></td>
699-
<td class="full" align="center">Yes</td>
699+
<td class="partial" align="center">
700+
<details><summary>Partial</summary>
701+
The line number associated with a macro invocation is not the line
702+
number of the first character of the macro name in the invocation.
703+
Additionally, Clang may not associate the line number of a pp-directive
704+
with the first <code>#</code> token. As these are recommended practices
705+
and not normative requirements, Clang's behavior is still conforming.
706+
</details>
707+
</td>
700708
</tr>
701709
<tr>
702710
<td>deprecated attribute</td>

0 commit comments

Comments
 (0)