public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/65896] New: Erroneous uninitialized variable access error in constexpr function with temporary variables
@ 2015-04-26 16:32 david at doublewise dot net
  2015-04-27  1:12 ` [Bug c++/65896] " david at doublewise dot net
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: david at doublewise dot net @ 2015-04-26 16:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 65896
           Summary: Erroneous uninitialized variable access error in
                    constexpr function with temporary variables
           Product: gcc
           Version: 5.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david at doublewise dot net
  Target Milestone: ---

file.cpp
==================================================
struct base{};

struct derived : base {
        constexpr derived():
                base{},
                m_value(0) {
        }
        constexpr derived(derived & other):
                base{},
                m_value(other) {
        }
        constexpr explicit operator int() const {
                return m_value;
        }
        int m_value;
};

constexpr int by_ref(derived && value) {
        return (derived(value), 0);
}

constexpr int value = by_ref(derived{});
==================================================

c++ -std=c++11 -o /dev/null file.cpp -c


gcc 4.8.3 and 4.9.3 and clang 3.5.0 successfully compile this program. gcc
5.1.1 fails with:

file.cpp:22:29:   in constexpr expansion of ‘by_ref(derived())’
file.cpp:22:39:   in constexpr expansion of ‘derived((* & value))’
file.cpp:10:16:   in constexpr expansion of ‘(& other)->derived::operator
int()’
file.cpp:22:39: error: accessing uninitialized member ‘derived::m_value’
 constexpr int value = by_ref(derived{});
                                       ^


Changing to C++1y / C++14 does not change this.
>From gcc-bugs-return-484675-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sun Apr 26 17:39:37 2015
Return-Path: <gcc-bugs-return-484675-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 9995 invoked by alias); 26 Apr 2015 17:39:37 -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 9971 invoked by uid 48); 26 Apr 2015 17:39:33 -0000
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/65892] gcc fails to implement N685 aliasing of union members
Date: Sun, 26 Apr 2015 17:39: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-Version: 5.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: msebor 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-65892-4-Mku0twnELx@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-65892-4@http.gcc.gnu.org/bugzilla/>
References: <bug-65892-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-04/txt/msg02227.txt.bz2
Content-length: 876

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|DUPLICATE                   |---

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Thanks for the pointer!  I had looked for a related bug report but couldn't
find it.

There's an important difference between the test cases in pr14319 and the one
here that's easy to overlook.  The rule only applies to structs defined in
unions, not those defined at file scope and only used to declare union members,
and to translation units in which the union definition is visible.  I would
recommend closing pr14319 as NOTABUG.  I have reopened this bug.


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

end of thread, other threads:[~2015-04-29  0:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-26 16:32 [Bug c++/65896] New: Erroneous uninitialized variable access error in constexpr function with temporary variables david at doublewise dot net
2015-04-27  1:12 ` [Bug c++/65896] " david at doublewise dot net
2015-04-27  8:39 ` [Bug c++/65896] [5/6 Regression] " redi at gcc dot gnu.org
2015-04-28 21:27 ` jason at gcc dot gnu.org
2015-04-29  0:58 ` jason at gcc dot gnu.org
2015-04-29  0:58 ` 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).