diff options
author | Jason Merrill <jason@redhat.com> | 2013-04-22 15:25:23 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2013-04-22 15:25:23 -0400 |
commit | ca45eca116b838230e9b169c2ee5579190593af8 (patch) | |
tree | 10c87e12e37e24ab255be35008913f1d619de9c0 /gcc | |
parent | d3d50a6185a224de3fb02c157cbf447f839d18e6 (diff) | |
download | gcc-ca45eca116b838230e9b169c2ee5579190593af8.zip gcc-ca45eca116b838230e9b169c2ee5579190593af8.tar.gz gcc-ca45eca116b838230e9b169c2ee5579190593af8.tar.bz2 |
N3323
* cvt.c (build_expr_type_conversion): Two conversions that return
the same type aren't necessarily ambiguous.
From-SVN: r198157
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/cvt.c | 23 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/context-conv1.C | 32 |
3 files changed, 51 insertions, 8 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 34f207f..57c2fc3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2013-04-22 Jason Merrill <jason@redhat.com> + N3323 + * cvt.c (build_expr_type_conversion): Two conversions that return + the same type aren't necessarily ambiguous. + N3648 * parser.c (cp_parser_lambda_introducer): Make lambda capture init pedwarn unconditional except in C++1y mode. diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index a3b7358..93be76a 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -1630,17 +1630,24 @@ build_expr_type_conversion (int desires, tree expr, bool complain) { if (winner) { - if (complain) + tree winner_type + = non_reference (TREE_TYPE (TREE_TYPE (winner))); + + if (!same_type_ignoring_top_level_qualifiers_p (winner_type, + candidate)) { - error ("ambiguous default type conversion from %qT", - basetype); - error (" candidate conversions include %qD and %qD", - winner, cand); + if (complain) + { + error ("ambiguous default type conversion from %qT", + basetype); + error (" candidate conversions include %qD and %qD", + winner, cand); + } + return error_mark_node; } - return error_mark_node; } - else - winner = cand; + + winner = cand; } } diff --git a/gcc/testsuite/g++.dg/cpp1y/context-conv1.C b/gcc/testsuite/g++.dg/cpp1y/context-conv1.C new file mode 100644 index 0000000..fe20cab --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/context-conv1.C @@ -0,0 +1,32 @@ +// N3323 + +#define assert(E) if(!(E))__builtin_abort(); + +template<class T> +class zero_init +{ +public: + zero_init( ) + : val( static_cast<T>(0) ) { } + zero_init( T val ) : val( val ) + { } + operator T & ( ) { return val; } + operator T ( ) const { return val; } +private: + T val; +}; + +void f() +{ + zero_init<int*> p; assert( p == 0 ); + p = new int(7); + assert( *p == 7 ); + delete p; // error! + + zero_init<int> i; assert( i == 0 ); + i = 7; + assert( i == 7 ); + switch( i ) { } // error! + + int *vp = new int[i]; +} |