public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kariya_mitsuru at hotmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/65642] [C++11] GCC rejects valid constant expression
Date: Tue, 31 Mar 2015 18:06:00 -0000	[thread overview]
Message-ID: <bug-65642-4-CQS8n2nkiO@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-65642-4@http.gcc.gnu.org/bugzilla/>

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.


  reply	other threads:[~2015-03-31 17:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-31 18:00 [Bug c++/65642] New: " kariya_mitsuru at hotmail dot com
2015-03-31 18:06 ` kariya_mitsuru at hotmail dot com [this message]
2015-04-01 11:00 ` [Bug c++/65642] [C++11] " 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-65642-4-CQS8n2nkiO@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).