[cfe-dev] SemaTemplateInstantiateDecl mistakenly issuing diag::warn_func_template_missing for templated deduction guides

Mário Feroldi via cfe-dev cfe-dev at lists.llvm.org
Wed Oct 25 07:33:58 PDT 2017


Following compilation shows the issue:

    $ clang++ --version
    clang version 6.0.0 (trunk 316414)
    Target: x86_64-unknown-linux-gnu
    Thread model: posix
    InstalledDir: /opt/compiler-explorer/clang-trunk/bin

    $ cat a.cpp
    template <typename T>
    struct S
    {
      template <typename U>
      S(U&&) {}
    };

    template <typename T>
    S(T) -> S<T>;

    int main()
    {
      S s(42);
    }

    $ clang++ -std=c++17 -Wundefined-func-template a.cpp
    a.cpp:13:7: warning: instantiation of function '<deduction guide for
S><int>' required here, but no definition is available
[-Wundefined-func-template]
        S s(42);
          ^
    a.cpp:9:1: note: forward declaration of template entity is here
        S(T) -> S<T>;
        ^
    a.cpp:13:7: note: add an explicit instantiation declaration to suppress
this warning if '<deduction guide for S><int>' is explicitly instantiated
in another translation unit
            S s(42);
              ^

I found out that this warning occurs at lib/Sema/
SemaTemplateInstantiateDecl.cpp:3809:

    else if (TSK == TSK_ImplicitInstantiation) { //< here
      if (AtEndOfTU && !getDiagnostics().hasErrorOccurred()) {
        Diag(PointOfInstantiation, diag::warn_func_template_missing)
          << Function;
        Diag(PatternDecl->getLocation(), diag::note_forward_template_decl);
        if (getLangOpts().CPlusPlus11)
          Diag(PointOfInstantiation, diag::note_inst_declaration_hint)
            << Function;
      }
    }

Shouldn't that check whether it's a deduction guide, or should it even
require a definition?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20171025/ef6ee0c4/attachment.html>


More information about the cfe-dev mailing list