@@ -8515,12 +8515,19 @@ check_return_expr (tree retval, bool *no_warning)
return NULL_TREE;
}
+ const tree saved_retval = retval;
+
if (processing_template_decl)
{
current_function_returns_value = 1;
+
if (check_for_bare_parameter_packs (retval))
- retval = error_mark_node;
- return retval;
+ return error_mark_node;
+
+ if (WILDCARD_TYPE_P (TREE_TYPE (DECL_RESULT (current_function_decl)))
+ || (retval != NULL_TREE
+ && type_dependent_expression_p (retval)))
+ return retval;
}
functype = TREE_TYPE (TREE_TYPE (current_function_decl));
@@ -8564,14 +8571,10 @@ check_return_expr (tree retval, bool *no_warning)
functype = type;
}
- /* When no explicit return-value is given in a function with a named
- return value, the named return value is used. */
result = DECL_RESULT (current_function_decl);
valtype = TREE_TYPE (result);
gcc_assert (valtype != NULL_TREE);
fn_returns_value_p = !VOID_TYPE_P (valtype);
- if (!retval && DECL_NAME (result) && fn_returns_value_p)
- retval = result;
/* Check for a return statement with no return value in a function
that's supposed to return a value. */
@@ -8656,6 +8659,13 @@ check_return_expr (tree retval, bool *no_warning)
warning (OPT_Weffc__, "%<operator=%> should return a reference to %<*this%>");
}
+ if (processing_template_decl)
+ {
+ /* We should not have altered the return value. */
+ gcc_assert (retval == saved_retval);
+ return retval;
+ }
+
/* The fabled Named Return Value optimization, as per [class.copy]/15:
[...] For a function with a class return type, if the expression
new file mode 100644
@@ -0,0 +1,11 @@
+// PR c++/18969
+// { dg-do compile { target c++14 } }
+
+template <typename T>
+struct A
+{
+ auto *f1 () { return; } // { dg-error "return-statement" }
+ auto &f2 () { return; } // { dg-error "return-statement" }
+
+ auto f3 () { return; } // { dg-bogus "return-statement" }
+};
new file mode 100644
@@ -0,0 +1,14 @@
+// PR c++/18969
+
+template <typename T>
+struct A
+{
+ int f1 () { return; } // { dg-error "return-statement" }
+ void f2 () { return 5; } // { dg-error "return-statement" }
+ T *f3 () { return; } // { dg-error "return-statement" }
+ typename T::f &f4 () { return; } // { dg-error "return-statement" }
+
+ T f5 () { return; } // { dg-bogus "return-statement" }
+ void f6 () { return (T)true; } // { dg-bogus "return-statement" }
+ typename T::f f7 () { return; } // { dg-bogus "return-statement" }
+};