__LINE__
and __FILE__
in macro replacement listThis issue has been automatically converted from the original issue lists and some formatting may not have been preserved.
Authors: WG14, Fred J. Tydeman
Date: 2015-06-23
Reference document: N1943
Submitted against: C11 / C17
Status: Closed
Converted from: n2396.htm
Based upon my reading of the standard, it appears that the following are ambiguous, so are a possible defect.
An example of that.
#line 500
#define MAC() __LINE__
#line 1000
int j = MAC(); /* is this 500 or 1000? */
However, 7.2.1.1 requires that the assert macro write information about the call that has a false expression. That information includes the __LINE__ and __FILE__ preprocessing macros. So, there is a requirement that this specific macro using __LINE__ and __FILE__ have the line number and file name of the invocation, not the line number and file name of the replacment list (in <assert.h>).
Add to 6.10.8.1, paragraph 1, item __LINE__:
The line number associated with a __LINE__ in a macro replacment list is the line number of the macro invocation.
Add to 6.10.8.1, paragraph 1, item __FILE__:
The source file name associated with a __FILE__ in a macro replacment list is the source file name of the macro invocation.
Comment from WG14 on 2016-10-21:
Oct 2015 meeting
The committee notes that these issues are also raised in the WG21 C++ committee document N4220. However, the committee also notes that among all implementations “nobody gets this wrong” and as such there is no actual confusion, and although there is sentiment that the standard might not perfectly express its intent, it is clear enough to warrant no change.
The committee believes that since there is no evidence of confusion over the intent of the standard in this area by any implementor that there is no defect worth correcting at this time.