public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66561] New: __builtin_LINE at al. should yield constant expressions
@ 2015-06-16 23:54 msebor at gcc dot gnu.org
  0 siblings, 0 replies; only message in thread
From: msebor at gcc dot gnu.org @ 2015-06-16 23:54 UTC (permalink / raw)
  To: gcc-bugs

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
>From gcc-bugs-return-489144-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Jun 17 00:03:46 2015
Return-Path: <gcc-bugs-return-489144-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 90303 invoked by alias); 17 Jun 2015 00:03:46 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 90242 invoked by uid 48); 17 Jun 2015 00:03:39 -0000
From: "hubicka at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug debug/66068] [6 Regression] error: type variant has different TYPE_VFIELD
Date: Wed, 17 Jun 2015 00:03:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: debug
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: hubicka at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 6.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-66068-4-f2fZTTbz5d@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-66068-4@http.gcc.gnu.org/bugzilla/>
References: <bug-66068-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-06/txt/msg01476.txt.bz2
Content-length: 389

https://gcc.gnu.org/bugzilla/show_bug.cgi?idf068

--- Comment #4 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
The issue is that C FE overloads TYPE_VFIELD by C_TYPE_INCOMPLETE_VARS and
dangle the pointers.
I already work around that in verify_type but the workaround assumes that only
main variants get C_TYPE_INCOMPLETE_VARS which is obviously wrong.  Will extend
the workaround.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-06-16 23:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-16 23:54 [Bug c++/66561] New: __builtin_LINE at al. should yield constant expressions msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).