Hi! As detailed in the PR, we would return operator "" _a (const char *) when looking for 2 argument const char *, std::size_t literal operator, because the first argument matched and we ran out of arguments and didn't check we have them all. The following patch fixes it. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.7.1?
I'm not 100% sure what should be done if some of the literal operators have default arguments. In particular, e.g. int operator "" _a (const char *, std::size_t = 0); int a = 123_a; I think the above isn't raw literal operator and thus it should be invalid rather than call operator "" _a ("123", 0), which would be what we do with the patch below. What about int operator "" _a (const char *); int operator "" _a (const char *, std::size_t = 0); int a = 123_a; ? Shall we just call oeprator "" _a ("123"); or emit error that we usually emit for: int foo (const char *); int foo (const char *, std::size_t = 0); int a = foo ("abc"); ? 2012-03-09 Jakub Jelinek <ja...@redhat.com> PR c++/52521 * parser.c (lookup_literal_operator): Return fn only if processed all arguments from args vector and argtypes is void_list_node. * g++.dg/cpp0x/udlit-args2.C: New test. --- gcc/cp/parser.c.jj 2012-03-06 17:02:09.000000000 +0100 +++ gcc/cp/parser.c 2012-03-09 22:02:31.934359645 +0100 @@ -3581,7 +3581,9 @@ lookup_literal_operator (tree name, VEC( TREE_TYPE (tparm)))) found = false; } - if (found) + if (found + && ix == VEC_length (tree, args) + && argtypes == void_list_node) return fn; } } --- gcc/testsuite/g++.dg/cpp0x/udlit-args2.C.jj 2012-03-09 22:07:56.138445779 +0100 +++ gcc/testsuite/g++.dg/cpp0x/udlit-args2.C 2012-03-09 22:08:37.742202965 +0100 @@ -0,0 +1,15 @@ +// PR c++/52521 +// { dg-do compile } +// { dg-options -std=c++11 } + +#include <cstddef> + +int operator "" _a (const char *); +int operator "" _a (const char *, std::size_t); +int a = 123_a; +int a2 = "abc"_a; + +int operator "" _b (const char *, std::size_t); +int operator "" _b (const char *); +int b = 123_b; +int b2 = "abc"_b; Jakub