Submitter:Fred J. Tydeman
Submission Date:2015-03-03
Document: WG14 N1911
Related: WG14 Defect Report 464, and section 6.5 of http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4220.pdf

Summary

Based upon my reading of the standard, it appears that the following are not specified, so are a possible defect.

Some examples of those cases.


  #line 500
  #define MAC(a,b) a,b,__LINE__

  #line 1000
 int j[] = { __LINE__, __\
LINE\
__,

  #line 2000
  #line __\
LINE\
__
  __LINE__,

  #line 3000
  #line \
\
\
__LINE__\
\
\
/**/
  __LINE__,

  MAC(__LINE__,__LINE__),

  MAC(
    __LINE__,
    __LINE__
  ),  __LINE__,

  M\
A\
C\
\
(\
\
__\
LINE\
__,\
__LINE__\
\
),
  __LINE__,

  M\
A\
C\
(
__\
LINE\
__,
__LINE__
),
  __LINE__,
  999 };

My testing of several compilers shows a large variation in behaviour. gcc, clang, pcc, Sun, Intel, Microsoft, Borland, all differ from each other for at least some of the above cases.

This appears to be interaction between phases of translation (5.1.1.2), line control (6.10.4), and mandatory macros (6.10.8.1).

It is clear to me from 6.10.4#2 that physical lines are used for line number (since it is a count of phase 1 new-lines). It is not logical lines after phase 2.

Suggested Technical Corrigendum

Add to 6.10.8.1, paragraph 1, item __LINE__:

The line number of a pp token is implementation defined to be the (physical) line number of either the first character or the last character of the pp token. The line number of a __LINE__ that spans multiple physical lines is implementation defined to be either the first line or the last line of that __LINE__. The line number of a __LINE__ in a macro body is the line number of the macro invocation. The line number of a macro invocation that spans multiple (physical or logical) lines is implementation defined to be either the line number of the first character of the macro name, the last character of the macro name or the closing ')' (if there is one).

Add to J.3.11