[Bug c++/126420] Rejects valid? deducing return type with expansion statement (empty)

"jakub at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126420

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The difference between
auto
foo ()
{
  template for (auto x : {})
    return 42;
  return 42L;
}
and
template <bool X>
auto
foo ()
{
  if (X)
    return 42;
  else
    return 42L;
}
is in the check_return_expr condition:
11591         if ((WILDCARD_TYPE_P (TREE_TYPE (DECL_RESULT
(current_function_decl)))
11592              && !FNDECL_USED_AUTO (current_function_decl))
11593             || (retval != NULL_TREE
11594                 && (TREE_TYPE (retval) == NULL_TREE
11595                     || WILDCARD_TYPE_P (TREE_TYPE (retval)))))
11596           goto dependent;
Now, in neither cases is retval dependent here, WILDCARD_TYPE_P is true in both
cases the first time we run into this.  But the difference is in in
FNDECL_USED_AUTO flag,
in the first testcase it is set because of start_preparsed_function:
20019     if (!processing_template_decl && type_uses_auto (restype))
20020       {
20021         FNDECL_USED_AUTO (decl1) = true;
20022         DECL_SAVED_AUTO_RETURN_TYPE (decl1) = restype;
20023       }
while in the second case it is not.  Perhaps we should just goto dependent;
also whenever in_expansion_stmt ?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.