===================================================================
@@ -6286,7 +6286,7 @@
tsubst_flags_t);
extern void check_template_keyword (tree);
extern bool check_raw_literal_operator (const_tree decl);
-extern bool check_literal_operator_args (const_tree, bool *, bool *);
+extern bool check_literal_operator_args (const_tree, bool *, bool *, bool *);
extern void maybe_warn_about_useless_cast (tree, tree, tsubst_flags_t);
extern tree cp_perform_integral_promotions (tree, tsubst_flags_t);
===================================================================
@@ -7849,6 +7849,7 @@
return NULL_TREE;
else if (UDLIT_OPER_P (DECL_NAME (decl)))
{
+ bool default_arg_p;
bool long_long_unsigned_p;
bool long_double_p;
const char *suffix = NULL;
@@ -7861,12 +7862,15 @@
if (DECL_NAMESPACE_SCOPE_P (decl))
{
- if (!check_literal_operator_args (decl, &long_long_unsigned_p,
+ if (!check_literal_operator_args (decl, &default_arg_p,
+ &long_long_unsigned_p,
&long_double_p))
{
error ("%qD has invalid argument list", decl);
return NULL_TREE;
}
+ if (default_arg_p)
+ warning (0, "%qD has default argument(s)", decl);
suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
if (long_long_unsigned_p)
===================================================================
@@ -9204,15 +9204,21 @@
argument types. */
bool
-check_literal_operator_args (const_tree decl,
+check_literal_operator_args (const_tree decl, bool *default_arg_p,
bool *long_long_unsigned_p, bool *long_double_p)
{
tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
+ *default_arg_p = false;
*long_long_unsigned_p = false;
*long_double_p = false;
if (processing_template_decl || processing_specialization)
- return argtypes == void_list_node;
+ {
+ if (argtypes && argtypes != void_list_node && TREE_PURPOSE (argtypes))
+ *default_arg_p = true;
+
+ return argtypes == void_list_node;
+ }
else
{
tree argtype;
@@ -9224,6 +9230,9 @@
argtype && argtype != void_list_node;
argtype = TREE_CHAIN (argtype))
{
+ if (TREE_PURPOSE (argtype))
+ *default_arg_p = true;
+
tree t = TREE_VALUE (argtype);
++arity;
@@ -9242,6 +9251,8 @@
argtype = TREE_CHAIN (argtype);
if (!argtype)
return false;
+ if (TREE_PURPOSE (argtype))
+ *default_arg_p = true;
t = TREE_VALUE (argtype);
if (maybe_raw_p && argtype == void_list_node)
return true;
@@ -9278,6 +9289,9 @@
if (!argtype)
return false; /* Found ellipsis. */
+ if (*default_arg_p)
+ return false;
+
if (arity != max_arity)
return false;
===================================================================
@@ -0,0 +1,22 @@
+// { dg-options -std=c++11 }
+
+#include <cstddef>
+
+int
+operator""_a(const char *, std::size_t = 0) // { dg-warning "has invalid argument list" }
+{
+ return 1;
+}
+
+int
+operator""_a(const char *)
+{
+ return 2;
+}
+
+int
+main()
+{
+ int i = 123_a; // OK, raw literal, not ambiguous.
+ int j = operator""_a("123"); // OK, raw literal, not ambiguous.
+}