[clang-tools-extra] [llvm] [clang] [clang] Accept recursive non-dependent calls to functions with deduced return type (PR #75456)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 4 02:27:56 PST 2024


================
@@ -640,3 +640,36 @@ namespace PR46637 {
   template<typename T> struct Y { T x; };
   Y<auto() -> auto> y; // expected-error {{'auto' not allowed in template argument}}
 }
+
+namespace GH71015 {
+
+// Check that there is no error in case a templated function is recursive and
+// has a placeholder return type.
+struct Node {
+  int value;
+  Node* left;
+  Node* right;
+};
+
+bool parse(const char*);
+Node* parsePrimaryExpr();
+
+auto parseMulExpr(auto node) { // cxx14-error {{'auto' not allowed in function prototype}}
+  if (node == nullptr) node = parsePrimaryExpr();
+  if (!parse("*")) return node;
+  return parseMulExpr(new Node{.left = node, .right = parsePrimaryExpr()});
----------------
Fznamznon wrote:

Added the test.

A note here is that It will only be rejected if the function instantiated because clang doesn't take into account return statements if the function is templated due to this part:

https://github.com/llvm/llvm-project/blob/11276563c81987791a2326950dbc3315a32dd709/clang/lib/Sema/SemaStmt.cpp#L3806

gcc rejects even if the function is not instantiated. msvc doesn't. https://compiler-explorer.com/z/hGc8M1esT


https://github.com/llvm/llvm-project/pull/75456


More information about the cfe-commits mailing list