public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51989] New: std::deque::iterator recognised as container
@ 2012-01-25 6:59 leonid at volnitsky dot com
2012-01-25 7:41 ` [Bug c++/51989] " leonid at volnitsky dot com
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: leonid at volnitsky dot com @ 2012-01-25 6:59 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51989
Bug #: 51989
Summary: std::deque::iterator recognised as container
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: leonid@volnitsky.com
Created attachment 26450
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26450
deque-bug.cc
I need is_container<T> template which would recognize if T is a container.
Code below works as expected. With exception for std::deque::iterator - gcc
can not compile code below:
------------------------------------------------------------------
#include <iostream>
#include <type_traits>
#include <vector>
#include <list>
#include <set>
#include <deque>
template <typename T>
struct is_container {
template <typename U>
static char test(
U* u,
typename U::const_iterator b = ((U*)0)->begin(),
typename U::const_iterator e = ((U*)0)->end()
);
template <typename U> static long test(...);
enum { value = sizeof test<T>(0) == 1 };
};
int main() {
std::cout << "void\t" << is_container< void
>::value << '\n';
std::cout << "int\t" << is_container< int >::value
<< '\n';
std::cout << "int*\t" << is_container< int*
>::value << '\n';
std::cout << "vector<int>\t" << is_container< std::vector<int>
>::value << '\n';
std::cout << "deque<int>\t" << is_container< std::deque<int>
>::value << '\n';
std::cout << "set<int>::iterator\t" << is_container<
std::set<int>::iterator >::value << '\n';
std::cout << "vector<int>::iterator\t" << is_container<
std::vector<int>::iterator >::value << '\n';
// gcc error
std::cout << "deque<int>::iterator\t" << is_container<
std::deque<int>::iterator >::value << '\n';
}
-----------------------------------------------------------------------
Compiling it with GCC (4.7.0-alpha20111203):
gcc -std=gnu++0x -Wall deque-bug.cc -o deque-bug
Produce following error:
deque-bug.cc: In instantiation of ‘struct
is_container<std::_Deque_iterator<int, int&, int*> >’:
deque-bug.cc:31:84: required from here
deque-bug.cc:18:7: error: ‘struct std::_Deque_iterator<int, int&, int*>’ has no
member named ‘begin’
deque-bug.cc:18:7: error: ‘struct std::_Deque_iterator<int, int&, int*>’ has no
member named ‘end’
Attached are source and -save-temps
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/51989] std::deque::iterator recognised as container
2012-01-25 6:59 [Bug c++/51989] New: std::deque::iterator recognised as container leonid at volnitsky dot com
@ 2012-01-25 7:41 ` leonid at volnitsky dot com
2012-01-25 8:12 ` leonid at volnitsky dot com
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: leonid at volnitsky dot com @ 2012-01-25 7:41 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51989
--- Comment #1 from Leonid Volnitsky <leonid at volnitsky dot com> 2012-01-25 05:03:14 UTC ---
Created attachment 26451
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26451
deque-bug.ii
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/51989] std::deque::iterator recognised as container
2012-01-25 6:59 [Bug c++/51989] New: std::deque::iterator recognised as container leonid at volnitsky dot com
2012-01-25 7:41 ` [Bug c++/51989] " leonid at volnitsky dot com
@ 2012-01-25 8:12 ` leonid at volnitsky dot com
2012-01-25 8:27 ` leonid at volnitsky dot com
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: leonid at volnitsky dot com @ 2012-01-25 8:12 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51989
--- Comment #2 from Leonid Volnitsky <leonid at volnitsky dot com> 2012-01-25 05:04:00 UTC ---
Created attachment 26452
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26452
deque-bug.s
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/51989] std::deque::iterator recognised as container
2012-01-25 6:59 [Bug c++/51989] New: std::deque::iterator recognised as container leonid at volnitsky dot com
2012-01-25 7:41 ` [Bug c++/51989] " leonid at volnitsky dot com
2012-01-25 8:12 ` leonid at volnitsky dot com
@ 2012-01-25 8:27 ` leonid at volnitsky dot com
2012-01-25 10:16 ` redi at gcc dot gnu.org
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: leonid at volnitsky dot com @ 2012-01-25 8:27 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51989
--- Comment #3 from Leonid Volnitsky <leonid at volnitsky dot com> 2012-01-25 05:04:56 UTC ---
Created attachment 26453
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26453
gcc error
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/51989] std::deque::iterator recognised as container
2012-01-25 6:59 [Bug c++/51989] New: std::deque::iterator recognised as container leonid at volnitsky dot com
` (2 preceding siblings ...)
2012-01-25 8:27 ` leonid at volnitsky dot com
@ 2012-01-25 10:16 ` redi at gcc dot gnu.org
2012-01-25 10:26 ` redi at gcc dot gnu.org
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2012-01-25 10:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51989
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-01-25 09:48:32 UTC ---
not a gcc bug, you're code is invalid - values of default arguments are not
part of the function type and do not take part in deduction
you can do it in C++11 with decltype
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/51989] std::deque::iterator recognised as container
2012-01-25 6:59 [Bug c++/51989] New: std::deque::iterator recognised as container leonid at volnitsky dot com
` (3 preceding siblings ...)
2012-01-25 10:16 ` redi at gcc dot gnu.org
@ 2012-01-25 10:26 ` redi at gcc dot gnu.org
2012-01-25 10:42 ` leonid at volnitsky dot com
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2012-01-25 10:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51989
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-01-25 09:55:25 UTC ---
However, I think it is a bug that this is rejected.
template <typename T>
struct is_container {
template <typename U, typename V = decltype(((U*)0)->begin())>
static char test( U* u);
template <typename U> static long test(...);
enum { value = sizeof test<T>(0) == 1 };
};
int main() {
return is_container< void >::value;
}
c.cc: In instantiation of ‘struct is_container<void>’:
c.cc:12:32: required from here
c.cc:3:27: error: ‘void*’ is not a pointer-to-object type
Jason, shouldn't deduction fail for ((U*)0)->foo() with U=void instead of
giving an error?
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/51989] std::deque::iterator recognised as container
2012-01-25 6:59 [Bug c++/51989] New: std::deque::iterator recognised as container leonid at volnitsky dot com
` (4 preceding siblings ...)
2012-01-25 10:26 ` redi at gcc dot gnu.org
@ 2012-01-25 10:42 ` leonid at volnitsky dot com
2012-01-25 12:30 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: leonid at volnitsky dot com @ 2012-01-25 10:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51989
--- Comment #6 from Leonid Volnitsky <leonid at volnitsky dot com> 2012-01-25 10:29:29 UTC ---
Also, new is_container<T> with decltype, have value == 0 for any, non-void
type.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/51989] std::deque::iterator recognised as container
2012-01-25 6:59 [Bug c++/51989] New: std::deque::iterator recognised as container leonid at volnitsky dot com
` (5 preceding siblings ...)
2012-01-25 10:42 ` leonid at volnitsky dot com
@ 2012-01-25 12:30 ` redi at gcc dot gnu.org
2012-01-25 12:42 ` leonid at volnitsky dot com
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2012-01-25 12:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51989
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-01-25 11:56:50 UTC ---
My code was only meant to show a possible problem with invalid expressions
using void* not to solve your issue. GCC's bugzilla isn't a tutorial site and
"my code doesn't work" isn't a compiler bug.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/51989] std::deque::iterator recognised as container
2012-01-25 6:59 [Bug c++/51989] New: std::deque::iterator recognised as container leonid at volnitsky dot com
` (6 preceding siblings ...)
2012-01-25 12:30 ` redi at gcc dot gnu.org
@ 2012-01-25 12:42 ` leonid at volnitsky dot com
2012-01-25 18:18 ` jason at gcc dot gnu.org
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: leonid at volnitsky dot com @ 2012-01-25 12:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51989
--- Comment #8 from Leonid Volnitsky <leonid at volnitsky dot com> 2012-01-25 12:29:22 UTC ---
I understand that. And thank you for giving me a hint and code for
is_container, it was more than I expected if it was non-bug. I've made the
comment only because I've thought that it might help to diagnose the problem,
if there is a bug after all.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/51989] std::deque::iterator recognised as container
2012-01-25 6:59 [Bug c++/51989] New: std::deque::iterator recognised as container leonid at volnitsky dot com
` (7 preceding siblings ...)
2012-01-25 12:42 ` leonid at volnitsky dot com
@ 2012-01-25 18:18 ` jason at gcc dot gnu.org
2012-01-25 21:19 ` paolo.carlini at oracle dot com
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: jason at gcc dot gnu.org @ 2012-01-25 18:18 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51989
--- Comment #9 from Jason Merrill <jason at gcc dot gnu.org> 2012-01-25 17:32:12 UTC ---
(In reply to comment #5)
> Jason, shouldn't deduction fail for ((U*)0)->foo() with U=void instead of
> giving an error?
Yep. Need to pass complain into build_x_arrow.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/51989] std::deque::iterator recognised as container
2012-01-25 6:59 [Bug c++/51989] New: std::deque::iterator recognised as container leonid at volnitsky dot com
` (8 preceding siblings ...)
2012-01-25 18:18 ` jason at gcc dot gnu.org
@ 2012-01-25 21:19 ` paolo.carlini at oracle dot com
2012-03-02 16:19 ` paolo at gcc dot gnu.org
2012-04-24 12:13 ` paolo.carlini at oracle dot com
11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-01-25 21:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51989
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2012-01-25
AssignedTo|unassigned at gcc dot |paolo.carlini at oracle dot
|gnu.org |com
Ever Confirmed|0 |1
--- Comment #10 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-01-25 20:29:07 UTC ---
Can do it.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/51989] std::deque::iterator recognised as container
2012-01-25 6:59 [Bug c++/51989] New: std::deque::iterator recognised as container leonid at volnitsky dot com
` (9 preceding siblings ...)
2012-01-25 21:19 ` paolo.carlini at oracle dot com
@ 2012-03-02 16:19 ` paolo at gcc dot gnu.org
2012-04-24 12:13 ` paolo.carlini at oracle dot com
11 siblings, 0 replies; 13+ messages in thread
From: paolo at gcc dot gnu.org @ 2012-03-02 16:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51989
--- Comment #11 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2012-03-02 16:18:34 UTC ---
Author: paolo
Date: Fri Mar 2 16:18:25 2012
New Revision: 184796
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=184796
Log:
/cp
2012-03-02 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/51989
* typeck2.c (build_x_arrow): Take a tsubst_flags_t argument and
propagate it.
* cp-tree.h (build_x_arrow): Adjust prototype.
* pt.c (tsubst_copy_and_build): Adjust call.
* parser.c (cp_parser_postfix_dot_deref_expression): Likewise.
/testsuite
2012-03-02 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/51989
* g++.dg/cpp0x/sfinae32.C: New.
Added:
trunk/gcc/testsuite/g++.dg/cpp0x/sfinae32.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/cp-tree.h
trunk/gcc/cp/parser.c
trunk/gcc/cp/pt.c
trunk/gcc/cp/typeck2.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/51989] std::deque::iterator recognised as container
2012-01-25 6:59 [Bug c++/51989] New: std::deque::iterator recognised as container leonid at volnitsky dot com
` (10 preceding siblings ...)
2012-03-02 16:19 ` paolo at gcc dot gnu.org
@ 2012-04-24 12:13 ` paolo.carlini at oracle dot com
11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-04-24 12:13 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51989
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.8.0
--- Comment #12 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-04-24 12:12:51 UTC ---
Fixed for 4.8.0.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2012-04-24 12:13 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-25 6:59 [Bug c++/51989] New: std::deque::iterator recognised as container leonid at volnitsky dot com
2012-01-25 7:41 ` [Bug c++/51989] " leonid at volnitsky dot com
2012-01-25 8:12 ` leonid at volnitsky dot com
2012-01-25 8:27 ` leonid at volnitsky dot com
2012-01-25 10:16 ` redi at gcc dot gnu.org
2012-01-25 10:26 ` redi at gcc dot gnu.org
2012-01-25 10:42 ` leonid at volnitsky dot com
2012-01-25 12:30 ` redi at gcc dot gnu.org
2012-01-25 12:42 ` leonid at volnitsky dot com
2012-01-25 18:18 ` jason at gcc dot gnu.org
2012-01-25 21:19 ` paolo.carlini at oracle dot com
2012-03-02 16:19 ` paolo at gcc dot gnu.org
2012-04-24 12:13 ` paolo.carlini at oracle dot com
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).