public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/67813] New: [C++14] copy-initialization of object with pointer member fails in constexpr function
@ 2015-10-02  5:07 Casey at Carter dot net
  2015-10-23 20:57 ` [Bug c++/67813] " jason at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: Casey at Carter dot net @ 2015-10-02  5:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 67813
           Summary: [C++14] copy-initialization of object with pointer
                    member fails in constexpr function
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Casey at Carter dot net
  Target Milestone: ---

r223851 fails to compile this correct program fragment:

struct Ptr {
  int* p;

  constexpr Ptr(int* p) noexcept : p{p} {}
  constexpr int& operator*() const {
    return *p;
  }
};

constexpr int f(int& i) {
  //Ptr first{&i}; // Works.
  Ptr first = &i;  // Error
  return *first;
}

constexpr int g() {
  int i = 42;
  return f(i);
}

static_assert(g() == 42);

with error:

~/gcc6-r228351/bin/g++ -std=c++14 foo.cpp -c
foo.cpp:21:1: error: non-constant condition for static assertion
 static_assert(g() == 42);
 ^
foo.cpp:21:16:   in constexpr expansion of ‘g()’
foo.cpp:18:11:   in constexpr expansion of ‘f(i)’
foo.cpp:13:11:   in constexpr expansion of ‘first.Ptr::operator*()’
foo.cpp:21:1: error: accessing uninitialized member ‘Ptr::p’

If the local is instead direct-initialized with "Ptr first{&i};", the program
correctly compiles without diagnostics. Results are identical if Ptr's member p
is type int& (with the constructor and operator* updated accordingly).
>From gcc-bugs-return-498581-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Oct 02 06:00:23 2015
Return-Path: <gcc-bugs-return-498581-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 8259 invoked by alias); 2 Oct 2015 06:00:20 -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 5854 invoked by uid 48); 2 Oct 2015 06:00:07 -0000
From: "segher at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug bootstrap/67789] Bootstrap failure with java starting at rev 228022
Date: Fri, 02 Oct 2015 06:00:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: dep_changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: bootstrap
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: segher at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
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: bug_status resolution
Message-ID: <bug-67789-4-oKunTR9eEb@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-67789-4@http.gcc.gnu.org/bugzilla/>
References: <bug-67789-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-10/txt/msg00136.txt.bz2
Content-length: 491

https://gcc.gnu.org/bugzilla/show_bug.cgi?idg789
Bug 67789 depends on bug 67788, which changed state.

Bug 67788 Summary: [6 Regression] bootstrap failure in libgfortran on powerpc-linux-gnu
https://gcc.gnu.org/bugzilla/show_bug.cgi?idg788

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


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

* [Bug c++/67813] [C++14] copy-initialization of object with pointer member fails in constexpr function
  2015-10-02  5:07 [Bug c++/67813] New: [C++14] copy-initialization of object with pointer member fails in constexpr function Casey at Carter dot net
@ 2015-10-23 20:57 ` jason at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: jason at gcc dot gnu.org @ 2015-10-23 20:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Fri Oct 23 20:57:05 2015
New Revision: 229270

URL: https://gcc.gnu.org/viewcvs?rev=229270&root=gcc&view=rev
Log:
        PR c++/67813
        * constexpr.c (cxx_eval_store_expression): Always use *valp if
        set.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-copy1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/constexpr.c


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

end of thread, other threads:[~2015-10-23 20:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-02  5:07 [Bug c++/67813] New: [C++14] copy-initialization of object with pointer member fails in constexpr function Casey at Carter dot net
2015-10-23 20:57 ` [Bug c++/67813] " jason 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).