public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/65642] New: GCC rejects valid constant expression
@ 2015-03-31 18:00 kariya_mitsuru at hotmail dot com
2015-03-31 18:06 ` [Bug c++/65642] [C++11] " kariya_mitsuru at hotmail dot com
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2015-03-31 18:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65642
Bug ID: 65642
Summary: GCC rejects valid constant expression
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/65642] [C++11] GCC rejects valid constant expression
2015-03-31 18:00 [Bug c++/65642] New: GCC rejects valid constant expression kariya_mitsuru at hotmail dot com
@ 2015-03-31 18:06 ` kariya_mitsuru at hotmail dot com
2015-04-01 11:00 ` mpolacek at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2015-03-31 18:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65642
Mitsuru Kariya <kariya_mitsuru at hotmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|GCC rejects valid constant |[C++11] GCC rejects valid
|expression |constant expression
--- Comment #1 from Mitsuru Kariya <kariya_mitsuru at hotmail dot com> ---
Please see the sample codes 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 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 2 ==========================
========================= error message 2 =========================
sample2.cpp:2:15: error: '((& s[0]) == ((& s[0]) + 1u))' is not a constant
expression
return found == last;
^
========================= error message 2 =========================
========================== sample code 3 ==========================
constexpr char s1[] = "s1";
constexpr char s2[] = "s2";
constexpr auto eq = (s1 + 0) == (s2 + 1);
int main() {}
========================== sample code 3 ==========================
========================= error message 3 =========================
sample3.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 3 =========================
The sample code 1 and 2 are compiled successfully on the 4.9.2, but they cause
an error on the head revision.
The sample code 3 causes an error on the 4.9.2 and the head revision.
These testcases are derived from bug 65398.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/65642] [C++11] GCC rejects valid constant expression
2015-03-31 18:00 [Bug c++/65642] New: GCC rejects valid constant expression kariya_mitsuru at hotmail dot com
2015-03-31 18:06 ` [Bug c++/65642] [C++11] " kariya_mitsuru at hotmail dot com
@ 2015-04-01 11:00 ` mpolacek at gcc dot gnu.org
2015-04-02 13:56 ` [Bug c++/65642] [5 Regression] " mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-04-01 11:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65642
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2015-04-01
CC| |mpolacek at gcc dot gnu.org
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Target Milestone|--- |5.0
Ever confirmed|0 |1
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I'll take a look.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/65642] [5 Regression] [C++11] GCC rejects valid constant expression
2015-03-31 18:00 [Bug c++/65642] New: GCC rejects valid constant expression kariya_mitsuru at hotmail dot com
2015-03-31 18:06 ` [Bug c++/65642] [C++11] " kariya_mitsuru at hotmail dot com
2015-04-01 11:00 ` mpolacek at gcc dot gnu.org
@ 2015-04-02 13:56 ` mpolacek at gcc dot gnu.org
2015-04-02 14:09 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-04-02 13:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65642
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Created attachment 35214
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35214&action=edit
pr65642.patch
Untested patch for example 1 and 3.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/65642] [5 Regression] [C++11] GCC rejects valid constant expression
2015-03-31 18:00 [Bug c++/65642] New: GCC rejects valid constant expression kariya_mitsuru at hotmail dot com
` (2 preceding siblings ...)
2015-04-02 13:56 ` [Bug c++/65642] [5 Regression] " mpolacek at gcc dot gnu.org
@ 2015-04-02 14:09 ` mpolacek at gcc dot gnu.org
2015-04-02 16:52 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-04-02 14:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65642
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #3)
> Created attachment 35214 [details]
> pr65642.patch
>
> Untested patch for example 1 and 3.
1 and 2. 3 is different.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/65642] [5 Regression] [C++11] GCC rejects valid constant expression
2015-03-31 18:00 [Bug c++/65642] New: GCC rejects valid constant expression kariya_mitsuru at hotmail dot com
` (3 preceding siblings ...)
2015-04-02 14:09 ` mpolacek at gcc dot gnu.org
@ 2015-04-02 16:52 ` mpolacek at gcc dot gnu.org
2015-04-07 17:19 ` [Bug c++/65642] " mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-04-02 16:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65642
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Thu Apr 2 16:51:27 2015
New Revision: 221843
URL: https://gcc.gnu.org/viewcvs?rev=221843&root=gcc&view=rev
Log:
PR c++/65642
* constexpr.c (cxx_eval_pointer_plus_expression): Call
cxx_eval_constant_expression on the first operand.
* g++.dg/cpp0x/constexpr-fold1.C: New test.
* g++.dg/cpp0x/constexpr-fold2.C: New test.
Added:
trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-fold1.C
trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-fold2.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/constexpr.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/65642] [C++11] GCC rejects valid constant expression
2015-03-31 18:00 [Bug c++/65642] New: GCC rejects valid constant expression kariya_mitsuru at hotmail dot com
` (4 preceding siblings ...)
2015-04-02 16:52 ` mpolacek at gcc dot gnu.org
@ 2015-04-07 17:19 ` mpolacek at gcc dot gnu.org
2021-12-20 7:24 ` pinskia at gcc dot gnu.org
2022-07-06 10:49 ` redi at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-04-07 17:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65642
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |NEW
Assignee|mpolacek at gcc dot gnu.org |unassigned at gcc dot gnu.org
Target Milestone|5.0 |6.0
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I think that fixing the third case is going to be harder, and doesn't look like
something that should be fixed in cp/constexpr.c.
While fold_comparison is able to fold the NE_EXPR here:
constexpr char s1[] = "s1";
constexpr char s2[] = "s2";
constexpr auto eq = (s2 + 2) != (s2 + 1);
it isn't able to fold it here:
constexpr char s1[] = "s1";
constexpr char s2[] = "s2";
constexpr auto eq = (s1 + 2) != (s2 + 1);
So not sure what to do here, but in any case, I think it is a GCC 6 material.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/65642] [C++11] GCC rejects valid constant expression
2015-03-31 18:00 [Bug c++/65642] New: GCC rejects valid constant expression kariya_mitsuru at hotmail dot com
` (5 preceding siblings ...)
2015-04-07 17:19 ` [Bug c++/65642] " mpolacek at gcc dot gnu.org
@ 2021-12-20 7:24 ` pinskia at gcc dot gnu.org
2022-07-06 10:49 ` redi at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-20 7:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65642
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=89074
--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think the last example is similar to bug 89074 comment #5.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/65642] [C++11] GCC rejects valid constant expression
2015-03-31 18:00 [Bug c++/65642] New: GCC rejects valid constant expression kariya_mitsuru at hotmail dot com
` (6 preceding siblings ...)
2021-12-20 7:24 ` pinskia at gcc dot gnu.org
@ 2022-07-06 10:49 ` redi at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-06 10:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65642
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEW |RESOLVED
Target Milestone|--- |12.0
--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Martin Liška from comment #10)
> Can the bug be marked as resolved?
At the time you asked, no, because the third example still failed.
But it compiles since r12-6382 (PR89074, as Andrew suggested).
So now it can be closed as fixed in GCC 12.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-07-06 10:49 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-31 18:00 [Bug c++/65642] New: GCC rejects valid constant expression kariya_mitsuru at hotmail dot com
2015-03-31 18:06 ` [Bug c++/65642] [C++11] " kariya_mitsuru at hotmail dot com
2015-04-01 11:00 ` mpolacek at gcc dot gnu.org
2015-04-02 13:56 ` [Bug c++/65642] [5 Regression] " mpolacek at gcc dot gnu.org
2015-04-02 14:09 ` mpolacek at gcc dot gnu.org
2015-04-02 16:52 ` mpolacek at gcc dot gnu.org
2015-04-07 17:19 ` [Bug c++/65642] " mpolacek at gcc dot gnu.org
2021-12-20 7:24 ` pinskia at gcc dot gnu.org
2022-07-06 10:49 ` redi 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).