From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19965 invoked by alias); 21 Nov 2012 12:13:00 -0000 Received: (qmail 19435 invoked by uid 48); 21 Nov 2012 12:12:20 -0000 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/55425] constexpr does not work in many situations (both built-in and user supplied literals) Date: Wed, 21 Nov 2012 12:13:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-11/txt/msg02025.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55425 --- Comment #1 from Jonathan Wakely 2012-11-21 12:12:19 UTC --- (In reply to comment #0) > > A return statement is not a return statement if the returned value is __func__ > (also true for non-standard identifiers like __PRETTY_FUNCTION__). > > // good > //static const char func[] = "function-name"; > //constexpr const char* x() { return func; } > > // bad > constexpr const char* x() { return __func__;} > > int main() { __builtin_puts(x()); return 0; } The standard says __func__ is a function-local variable, defined as if by constexpr const char* x() { static const char __func__[] = "function-name "; return __func__; } Clearly this is not a valid constexpr function. Changing this would be an extension. > Situation 2: user literals > -------------------------- > > The (obviously constant) string that the compiler builds from the literal is > not constant according to the compiler: > > #include > > constexpr int valid_bin_number(const char* c) { return *c ? ((*c == '1' || *c > == '0') ? valid_bin_number(c+1) : false ) : true; } > > unsigned int operator"" _bin(const char* str) > { > static_assert(valid_bin_number(str), "not a binary number"); 'str' is not a constant expression, so 'valid_bin_number(str)' is not a constant expression either. This is not a bug. > Situation 3: __m128i type > -------------------------- > > Assigning a literal value to a constexpr __m128 fails because the literal is > not a literal. No, the error says __m128 is not a literal type, which I assume is true. Changing that would be an enhancement request.