This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/66561] New: __builtin_LINE at al. should yield constant expressions
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 16 Jun 2015 23:54:31 +0000
- Subject: [Bug c++/66561] New: __builtin_LINE at al. should yield constant expressions
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66561
Bug ID: 66561
Summary: __builtin_LINE at al. should yield constant
expressions
Product: gcc
Version: 5.1.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
The manual documents the built-in function __builtin_LINE as follows:
This function is the equivalent to the preprocessor __LINE__ macro and returns
the line number of the invocation of the built-in. In a C++ default argument
for a function F, it gets the line number of the call to F.
but as the test case below shows, the function isn't quite the equivalent of
__LINE__ in one important aspect: __LINE__ is a constant expression, while
__builtin_LINE() is not. (Similarly for __builtin_FILE() and
__builtin_FUNCTION() in C++.)
I propose to treat __builtin_LINE() as a constant integer expression in C, and
all the functions as constexpr C++.
In C++, the Source-Code Information Capture proposal, N4519 in the latest WG21
mailing, depends on it:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4519.pdf
$ cat z.cpp && ~/bin/gcc-5.1.0/bin/g++ -Wall -std=c++11 z.cpp)
struct source_location {
const int ln;
constexpr source_location(int ln = __builtin_LINE ()) noexcept: ln (ln) { }
constexpr int line () const noexcept { return ln; }
static constexpr source_location current () noexcept {
return source_location (__builtin_LINE ());
}
};
#define LINE 123
#line LINE
constexpr source_location loc = source_location::current ();
static_assert (loc.line () == LINE, "source_location::line");
z.cpp:123:59: in constexpr expansion of âsource_location::current()â
z.cpp:6:46: error: â__builtin_LINE()â is not a constant expression
return source_location (__builtin_LINE ());
^
z.cpp:124:1: error: non-constant condition for static assertion