public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization
@ 2015-03-12 11:11 kariya_mitsuru at hotmail dot com
  2015-03-13  9:52 ` [Bug c++/65398] [5 Regression] " mpolacek at gcc dot gnu.org
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2015-03-12 11:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

            Bug ID: 65398
           Summary: [C++11] GCC rejects constexpr variable definitions
                    with valid initialization
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kariya_mitsuru at hotmail dot com

Created attachment 35017
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35017&action=edit
g++ -v

The sample code below should be compiled successfully but gcc 5.0 rejects it.

================= sample code =================
constexpr char s[] = "abc";
constexpr char c = *(&s[0] + 1);

int main() {}
================= sample code =================

cf. http://melpon.org/wandbox/permlink/jRbgl6YCTXHSspI9


Note that gcc 4.9.2 accepts it.

cf. http://melpon.org/wandbox/permlink/bwuaSYUvgwAjRTfo


Note also that gcc 5.0 accepts if "&s[0]" is replaced with "s".

================= sample code =================
constexpr char s[] = "abc";
constexpr char c = *(s + 1);

int main() {}
================= sample code =================
cf. http://melpon.org/wandbox/permlink/sy0THyfnSq6XCT0L


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
@ 2015-03-13  9:52 ` mpolacek at gcc dot gnu.org
  2015-03-13 10:43 ` mpolacek at gcc dot gnu.org
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-13  9:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-03-13
                 CC|                            |mpolacek at gcc dot gnu.org
   Target Milestone|---                         |5.0
            Summary|[C++11] GCC rejects         |[5 Regression] [C++11] GCC
                   |constexpr variable          |rejects constexpr variable
                   |definitions with valid      |definitions with valid
                   |initialization              |initialization
     Ever confirmed|0                           |1

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed, started with r214941, which did away with try_move_mult_to_index
that tried to replace &a[idx] p+ s * delta with &a[idx + delta].  I think the
fix is to teach cxx_fold_indirect_ref to do similar transformation.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
  2015-03-13  9:52 ` [Bug c++/65398] [5 Regression] " mpolacek at gcc dot gnu.org
@ 2015-03-13 10:43 ` mpolacek at gcc dot gnu.org
  2015-03-18 13:28 ` rguenth at gcc dot gnu.org
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-13 10:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
So let me try that out.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
  2015-03-13  9:52 ` [Bug c++/65398] [5 Regression] " mpolacek at gcc dot gnu.org
  2015-03-13 10:43 ` mpolacek at gcc dot gnu.org
@ 2015-03-18 13:28 ` rguenth at gcc dot gnu.org
  2015-03-21  0:10 ` mpolacek at gcc dot gnu.org
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-03-18 13:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
                   ` (2 preceding siblings ...)
  2015-03-18 13:28 ` rguenth at gcc dot gnu.org
@ 2015-03-21  0:10 ` mpolacek at gcc dot gnu.org
  2015-03-21  0:25 ` mpolacek at gcc dot gnu.org
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-21  0:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Fri Mar 20 21:53:40 2015
New Revision: 221544

URL: https://gcc.gnu.org/viewcvs?rev=221544&root=gcc&view=rev
Log:
    PR c++/65398
    * constexpr.c (cxx_fold_indirect_ref): Transform *(&A[i] p+ j) into
    A[i + j].

    * g++.dg/cpp0x/pr65398.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/pr65398.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/constexpr.c
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
                   ` (3 preceding siblings ...)
  2015-03-21  0:10 ` mpolacek at gcc dot gnu.org
@ 2015-03-21  0:25 ` mpolacek at gcc dot gnu.org
  2015-03-29 19:32 ` jason at gcc dot gnu.org
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-21  0:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed for GCC 5.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
                   ` (4 preceding siblings ...)
  2015-03-21  0:25 ` mpolacek at gcc dot gnu.org
@ 2015-03-29 19:32 ` jason at gcc dot gnu.org
  2015-03-30  8:18 ` kariya_mitsuru at hotmail dot com
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: jason at gcc dot gnu.org @ 2015-03-29 19:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |jason at gcc dot gnu.org
         Resolution|FIXED                       |---

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
Another testcase, derived from one attached to bug 65509:

char s[] = "s";

#define SA(X) static_assert((X),#X);
SA((&s[0] + 0) != (&s[0] + 1));

here we aren't indirecting the addresses, so I think cxx_fold_indirect_ref
isn't the right place for the fix.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
                   ` (5 preceding siblings ...)
  2015-03-29 19:32 ` jason at gcc dot gnu.org
@ 2015-03-30  8:18 ` kariya_mitsuru at hotmail dot com
  2015-03-30  8:59 ` daniel.kruegler at googlemail dot com
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2015-03-30  8:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

--- Comment #6 from Mitsuru Kariya <kariya_mitsuru at hotmail dot com> ---
I also found a strange behavior like below.

============================== sample code ==============================
#include <iostream>

constexpr char s1[] = "s1";
constexpr char s2[] = "s2";

bool f(const char* p1, const char* p2) { return p1 == p2; }

constexpr auto eq1 =   &s1[sizeof(s1)] == &s2[0];
          auto eq2 = f(&s1[sizeof(s1)],   &s2[0]);

int main()
{
    std::cout << static_cast<const void*>(&s1[sizeof(s1)]) << std::endl;
    std::cout << static_cast<const void*>(&s2[0]) << std::endl;
    std::cout << std::boolalpha << eq1 << ", " << eq2 << std::endl;
}
============================== sample code ==============================
============================== output ==============================
0x400bb8
0x400bb8
false, true
============================== output ==============================
cf. http://melpon.org/wandbox/permlink/Iu0rFFMgeYqT98fo


I think that it should either

1) cause a compilation error at the definition of the eq1 if the result of
"&s1[sizeof(s1)] == &s2[0]" is "unspecified".

or

2) output "true, true" because both the "&s1[sizeof(s1)]" and "&s2[0]"
represent the same address.

but I am not sure which behavior is appropriate.

(I cannot find an explicit description by which comparison between one past the
end pointer and another object's pointer is "unspecified behavior", in the C++
standard.)


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
                   ` (6 preceding siblings ...)
  2015-03-30  8:18 ` kariya_mitsuru at hotmail dot com
@ 2015-03-30  8:59 ` daniel.kruegler at googlemail dot com
  2015-03-30  9:07 ` kariya_mitsuru at hotmail dot com
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2015-03-30  8:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

--- Comment #7 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
(In reply to Mitsuru Kariya from comment #6)
> I think that it should either
> 
> 1) cause a compilation error at the definition of the eq1 if the result of
> "&s1[sizeof(s1)] == &s2[0]" is "unspecified".
> 
> or
> 
> 2) output "true, true" because both the "&s1[sizeof(s1)]" and "&s2[0]"
> represent the same address.
> 
> but I am not sure which behavior is appropriate.
> 
> (I cannot find an explicit description by which comparison between one past
> the end pointer and another object's pointer is "unspecified behavior", in
> the C++ standard.)

According to the current resolution of CWG 1652,

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1652

this comparison should be considered as unspecified and the code should be
rejected.
>From gcc-bugs-return-482219-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Mar 30 07:58:46 2015
Return-Path: <gcc-bugs-return-482219-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 125276 invoked by alias); 30 Mar 2015 07:58:45 -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 125252 invoked by uid 48); 30 Mar 2015 07:58:42 -0000
From: "vries at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/65511] transform_to_exit_first_loop looses edge probabilities
Date: Mon, 30 Mar 2015 09:01:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: tree-optimization
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords: patch
X-Bugzilla-Severity: trivial
X-Bugzilla-Who: vries 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-Flags:
X-Bugzilla-Changed-Fields: keywords
Message-ID: <bug-65511-4-cUmSDn9Iee@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-65511-4@http.gcc.gnu.org/bugzilla/>
References: <bug-65511-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-03/txt/msg03363.txt.bz2
Content-length: 382

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

vries at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch

--- Comment #5 from vries at gcc dot gnu.org ---
https://gcc.gnu.org/ml/gcc-patches/2015-03/msg01527.html


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
                   ` (7 preceding siblings ...)
  2015-03-30  8:59 ` daniel.kruegler at googlemail dot com
@ 2015-03-30  9:07 ` kariya_mitsuru at hotmail dot com
  2015-03-30 10:35 ` mpolacek at gcc dot gnu.org
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2015-03-30  9:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

--- Comment #8 from Mitsuru Kariya <kariya_mitsuru at hotmail dot com> ---
Oh, thanks a lot!  I've got it.
(And I've understood the reason why clang rejects it ;).)


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
                   ` (8 preceding siblings ...)
  2015-03-30  9:07 ` kariya_mitsuru at hotmail dot com
@ 2015-03-30 10:35 ` mpolacek at gcc dot gnu.org
  2015-03-30 13:30 ` mpolacek at gcc dot gnu.org
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-30 10:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Jason Merrill from comment #5)
> Another testcase, derived from one attached to bug 65509:
> 
> char s[] = "s";
> 
> #define SA(X) static_assert((X),#X);
> SA((&s[0] + 0) != (&s[0] + 1));
> 
> here we aren't indirecting the addresses, so I think cxx_fold_indirect_ref
> isn't the right place for the fix.

Yeah.  I think I'll have to massage the POINTER_PLUS_EXPR case in
cxx_eval_constant_expression so we fold the &s[0] + 0 stuff even when we're not
dereferencing the expr.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
                   ` (9 preceding siblings ...)
  2015-03-30 10:35 ` mpolacek at gcc dot gnu.org
@ 2015-03-30 13:30 ` mpolacek at gcc dot gnu.org
  2015-03-30 20:48 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-30 13:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

--- Comment #10 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I have a patch.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
                   ` (10 preceding siblings ...)
  2015-03-30 13:30 ` mpolacek at gcc dot gnu.org
@ 2015-03-30 20:48 ` mpolacek at gcc dot gnu.org
  2015-03-30 21:12 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-30 20:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

--- Comment #11 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Mon Mar 30 18:39:17 2015
New Revision: 221777

URL: https://gcc.gnu.org/viewcvs?rev=221777&root=gcc&view=rev
Log:
    PR c++/65398
    * constexpr.c (cxx_fold_indirect_ref): Don't perform the
     *(&A[i] p+ j) => A[i + j] transformation here.
    (cxx_eval_pointer_plus_expression): New function.
    (cxx_eval_constant_expression): Use it here.

    * g++.dg/cpp0x/pr65398-2.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/pr65398-2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/constexpr.c
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
                   ` (11 preceding siblings ...)
  2015-03-30 20:48 ` mpolacek at gcc dot gnu.org
@ 2015-03-30 21:12 ` mpolacek at gcc dot gnu.org
  2015-03-31 16:19 ` kariya_mitsuru at hotmail dot com
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-30 21:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #12 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Hopefully fixed for real this time around.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
                   ` (12 preceding siblings ...)
  2015-03-30 21:12 ` mpolacek at gcc dot gnu.org
@ 2015-03-31 16:19 ` kariya_mitsuru at hotmail dot com
  2015-03-31 16:50 ` mpolacek at gcc dot gnu.org
  2015-03-31 18:48 ` mpolacek at gcc dot gnu.org
  15 siblings, 0 replies; 17+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2015-03-31 16:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

--- Comment #13 from Mitsuru Kariya <kariya_mitsuru at hotmail dot com> ---
Thank you for your quick response.
But unfortunately, I found problems like below.

========================== sample code 1 ==========================
constexpr char f(const char* s)
{
        return *(s + 1);
}

constexpr char s[] = "ss";

constexpr auto c = f(&s[0]);

int main() {}
========================== sample code 1 ==========================
========================= error message 1 =========================
sample1.cpp:8:21:   in constexpr expansion of 'f((& s[0]))'
sample1.cpp:8:27: error: '*(s + 1u)' is not a constant expression
 constexpr auto c = f(&s[0]);
                           ^
========================= error message 1 =========================

========================== sample code 2 ==========================
constexpr char s1[] = "s1";
constexpr char s2[] = "s2";

constexpr auto eq = (s1 + 0) == (s2 + 1);

int main() {}
========================== sample code 2 ==========================
========================= error message 2 =========================
sample2.cpp:4:30: error: '(((const char*)(& s1)) == (((const char*)(& s2)) +
1u))' is not a constant expression
 constexpr auto eq = (s1 + 0) == (s2 + 1);
                              ^
========================= error message 2 =========================

========================== sample code 3 ==========================
constexpr bool g(char const* found, char const* last) {
        return found == last;
}

constexpr bool f(const char* s)
{
        return g(s, s + 1);
}

constexpr char s[] = "ss";

constexpr auto b = f(&s[0]);

int main() {}
========================== sample code 3 ==========================
========================= error message 3 =========================
sample3.cpp:2:15: error: '((& s[0]) == ((& s[0]) + 1u))' is not a constant
expression
  return found == last;
               ^
========================= error message 3 =========================

The sample code 1 is compiled successfully on both the 4.9.2 and the previous
revision but it causes an error on the head revision.
The sample code 2 causes an error on the 4.9.2, the previous revision and the
head revision.
The sample code 3 is compiled successfully on the 4.9.2, but it causes an error
on both the previous revision and the head revision.

(I use a constexpr library and its tests are passed on 4.9.2 but are failed on
5.0.0.)


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
                   ` (13 preceding siblings ...)
  2015-03-31 16:19 ` kariya_mitsuru at hotmail dot com
@ 2015-03-31 16:50 ` mpolacek at gcc dot gnu.org
  2015-03-31 18:48 ` mpolacek at gcc dot gnu.org
  15 siblings, 0 replies; 17+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-31 16:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

--- Comment #14 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I see.  Luckily these didn't regress with my fix for this PR, so I think these
are separate issues.  Could you please open a new PR?  I'll see if I can fix
these new ones.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
  2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
                   ` (14 preceding siblings ...)
  2015-03-31 16:50 ` mpolacek at gcc dot gnu.org
@ 2015-03-31 18:48 ` mpolacek at gcc dot gnu.org
  15 siblings, 0 replies; 17+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-31 18:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398

--- Comment #16 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Mitsuru Kariya from comment #15)
> I have opened a new issue bug 65642.

Thanks.

> (Sorry, I made a mistake in operation so its description is empty.)

That is fine.  :)


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2015-03-31 18:00 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-12 11:11 [Bug c++/65398] New: [C++11] GCC rejects constexpr variable definitions with valid initialization kariya_mitsuru at hotmail dot com
2015-03-13  9:52 ` [Bug c++/65398] [5 Regression] " mpolacek at gcc dot gnu.org
2015-03-13 10:43 ` mpolacek at gcc dot gnu.org
2015-03-18 13:28 ` rguenth at gcc dot gnu.org
2015-03-21  0:10 ` mpolacek at gcc dot gnu.org
2015-03-21  0:25 ` mpolacek at gcc dot gnu.org
2015-03-29 19:32 ` jason at gcc dot gnu.org
2015-03-30  8:18 ` kariya_mitsuru at hotmail dot com
2015-03-30  8:59 ` daniel.kruegler at googlemail dot com
2015-03-30  9:07 ` kariya_mitsuru at hotmail dot com
2015-03-30 10:35 ` mpolacek at gcc dot gnu.org
2015-03-30 13:30 ` mpolacek at gcc dot gnu.org
2015-03-30 20:48 ` mpolacek at gcc dot gnu.org
2015-03-30 21:12 ` mpolacek at gcc dot gnu.org
2015-03-31 16:19 ` kariya_mitsuru at hotmail dot com
2015-03-31 16:50 ` mpolacek at gcc dot gnu.org
2015-03-31 18:48 ` mpolacek 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).