public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58162] New: [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)'
@ 2013-08-14 22:18 ppluzhnikov at google dot com
2013-10-03 5:15 ` [Bug c++/58162] " james.dennett at gmail dot com
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: ppluzhnikov at google dot com @ 2013-08-14 22:18 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58162
Bug ID: 58162
Summary: [C++11] bogus error: use of deleted function
'constexpr A::A(const A&)'
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ppluzhnikov at google dot com
Google ref b/10272620
/// --- cut ---
struct A {
A();
A(A&&);
};
struct B {
A const a = A();
};
B b;
/// --- cut ---
Using trunk: g++ (GCC) 4.9.0 20130814 (experimental)
g++ -c -std=c++11 t.cc
t.cc: In constructor ‘constexpr B::B()’:
t.cc:6:8: error: use of deleted function ‘constexpr A::A(const A&)’
struct B {
^
t.cc:1:8: note: ‘constexpr A::A(const A&)’ is implicitly declared as deleted
because ‘A’ declares a move constructor or move assignment operator
struct A {
^
t.cc: At global scope:
t.cc:10:3: note: synthesized method ‘constexpr B::B()’ first required here
B b;
^
Analysys by jdennett
This is under 8.5p17 (via other sections... 9.2[Class Members]p4 leads
to 12.6.2, and 12.6.2p8 says "if the entity is a non-static data member
that has a brace-or-equal-initializer, the entity is initialized as
specified in 8.5"), and (I believe) should be the same initialization
as for a local variable declared as
A const a = A();
(All references above are in the C++14 CD.)
8.5p17 says:
"If the destination type is a (possibly cv-qualified) class type:
— If the initialization is direct-initialization, or if it is
copy-initialization where the cv-unqualified version of the source type
is the same class as, or a derived class of, the class of the destination,
constructors are considered."
We're in the case of copy-initialization where the cv-unqualified
version of the source type is A, and the destination type is "const A",
but arguably "the class of the destination" is A (because const A isn't
a class).
So I believe that this should fall into the same case as
direct-initialization, overload resolution should pick the A::A(A&&)
move constructor, and all should be good.
Wild guesses about how this might go wrong in the compiler:
It might be that G++ is checking whether the cv-unqualified version of
the source type is the same as the destination type (rather than the same
as the cv-unqualified version of the destination type, which is the class
here). If so, it would fall into the main case of copy-initialization,
which creates a temporary of the target type. That should still work,
but if the temporary were (incorrectly) considered to be a "const A"
rather than an "A" then initializing from it would attempt to use the
(deleted) copy constructor.
Seeing if changing A(A&&) to A(A const&&) changes anything might be
informative, or having both overloads present.
Changing 'A(A&&);' to 'A(const AA&&);' or adding it as overload does fix
the compilation problem.
Further patch from jdennett:
With the following hack, the testcase compiles.
$ svn diff gcc
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c (revision 201651)
+++ gcc/cp/parser.c (working copy)
@@ -23002,7 +23002,10 @@
if (BRACE_ENCLOSED_INITIALIZER_P (parsed_arg)
&& CONSTRUCTOR_IS_DIRECT_INIT (parsed_arg))
flags = LOOKUP_NORMAL;
- parsed_arg = digest_init_flags (TREE_TYPE (decl), parsed_arg, flags);
+ // TODO(jdennett): Something better than this, and work out how
+ // to test it.
+ parsed_arg = digest_init_flags (TYPE_MAIN_VARIANT (TREE_TYPE (decl)),
+ parsed_arg, flags);
}
}
>From gcc-bugs-return-427866-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Aug 14 22:31:21 2013
Return-Path: <gcc-bugs-return-427866-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 15239 invoked by alias); 14 Aug 2013 22:31:21 -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 15221 invoked by uid 48); 14 Aug 2013 22:31:20 -0000
From: "ppluzhnikov at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/58163] New: [C++11] Pedantic assert on str[str.size()] is wrong in C++11
Date: Wed, 14 Aug 2013 22:31:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: libstdc++
X-Bugzilla-Version: unknown
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: ppluzhnikov at google dot com
X-Bugzilla-Status: UNCONFIRMED
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_id short_desc product version bug_status bug_severity priority component assigned_to reporter
Message-ID: <bug-58163-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: 2013-08/txt/msg00790.txt.bz2
Content-length: 1985
http://gcc.gnu.org/bugzilla/show_bug.cgi?idX163
Bug ID: 58163
Summary: [C++11] Pedantic assert on str[str.size()] is wrong in
C++11
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: ppluzhnikov at google dot com
Google ref b/10322506
/// --- cut ---
#include <string>
int main()
{
const std::string cs;
std::string s;
if (cs[0] != '\0') return 1;
if (s[0] != '\0') return 2;
return 0;
}
/// --- cut ---
Using trunk gcc g++ (GCC) 4.9.0 20130814 (experimental)
g++ -g t.cc -D_GLIBCXX_DEBUG_PEDANTIC -D_GLIBCXX_DEBUG -std=c++11 && ./a.out
/gcc-svn-install/include/c++/4.9.0/bits/basic_string.h:848:
std::basic_string<_CharT, _Traits, _Alloc>::reference std::basic_string<_CharT,
_Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits,
_Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>;
_Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits,
_Alloc>::reference = char&; std::basic_string<_CharT, _Traits,
_Alloc>::size_type = long unsigned int]: Assertion '__pos < size()' failed.
In C++98:
21.3.4 basic_string element access [lib.string.access]
const_reference operator[](size_type pos) const;
reference operator[](size_type pos);
Returns: If pos < size(), returns data()[pos]. Otherwise, if pos == size(),
the const version returns charT().
Otherwise, the behavior is undefined. <<== PEDASSERT catches this.
However, in C++11:
21.4.5 basic_string element access [string.access]
const_reference operator[](size_type pos) const;
reference operator[](size_type pos);
Requires: pos <= size().
Returns: *(begin() + pos) if pos < size(), otherwise a reference to an object
of type T with value charT(); the referenced value shall not be modied.
Note removal of undefined behavior.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-11-24 2:54 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-14 22:18 [Bug c++/58162] New: [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)' ppluzhnikov at google dot com
2013-10-03 5:15 ` [Bug c++/58162] " james.dennett at gmail dot com
2013-10-31 14:42 ` jason at gcc dot gnu.org
2013-10-31 14:51 ` jason at gcc dot gnu.org
2013-10-31 17:37 ` james.dennett at gmail dot com
2013-11-24 2:44 ` jason at gcc dot gnu.org
2013-11-24 2:54 ` 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).