From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 323 invoked by alias); 19 Oct 2011 12:55:04 -0000 Received: (qmail 312 invoked by uid 22791); 19 Oct 2011 12:55:03 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 19 Oct 2011 12:54:46 +0000 From: "daniel.kruegler at googlemail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/50785] [C++0x] static constexpr double undefined reference Date: Wed, 19 Oct 2011 12:55: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-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: daniel.kruegler at googlemail dot com X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-10/txt/msg01953.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D50785 --- Comment #8 from Daniel Kr=C3=BCgler 2011-10-19 12:54:24 UTC --- I agree that the test case should require the definition of the static memb= er, the actual reason being that the constraint in 3.2 p2, "[..] unless it is an object that satisfies the requirements for appearing = in a constant expression [..]" is not satisfied, because the operator* of complex is not constexpr. Changi= ng the reference to std::complex by template struct complex { private: T data[2]; public: constexpr complex(T r =3D 0, T i =3D 0) : data{r, i} {} constexpr T real() { return data[0]; } constexpr T imag() { return data[1]; } }; template constexpr complex operator*(const complex& lhs, const T& rhs) { return complex(lhs.real() * rhs, lhs.imag() * rhs); } also fixes the initial problem, because now the expression complex(0,1)*test::value satisfies the criteria to appear in a constant expression. But I think that the replacement code complex x =3D complex(0,1)*(1*test::value); should also require the definition of test::value. It could be, that the compiler now reduces the scope of the analysis to the sub-expression (1*test::value). If so, this is either a compiler defect or a core language defect, I'm not sure. It is arguable that the description "[..] unless it is an object that satisfies the requirements for appearing = in a constant expression [..]" is somewhat misleading, because it focuses on the object and not on the expression where it is part of. This could be related to CWG #712 in this c= ase.