SemaTemplateInstantiateDecl mistakenly issuing diag::warn_func_template_missing for templated deduction guides

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

SemaTemplateInstantiateDecl mistakenly issuing diag::warn_func_template_missing for templated deduction guides

Eric Fiselier via cfe-dev
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?

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: SemaTemplateInstantiateDecl mistakenly issuing diag::warn_func_template_missing for templated deduction guides

Eric Fiselier via cfe-dev
The post-commit review thread for this warning concluded that this warning probably shouldn't be on by default, but looks like it didn't get disabled.

On Wed, Oct 25, 2017 at 2:33 PM, Mário Feroldi via cfe-dev <[hidden email]> wrote:
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?

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: SemaTemplateInstantiateDecl mistakenly issuing diag::warn_func_template_missing for templated deduction guides

Eric Fiselier via cfe-dev
On Wed, Oct 25, 2017 at 12:16 PM, Nico Weber via cfe-dev
<[hidden email]> wrote:
> The post-commit review thread for this warning concluded that this warning
> probably shouldn't be on by default, but looks like it didn't get disabled.

We don't usually add off-by-default diagnostics because almost no one
ever enables them, so perhaps the diagnostic should simply be removed
if it's low-value?

~Aaron

>
> On Wed, Oct 25, 2017 at 2:33 PM, Mário Feroldi via cfe-dev
> <[hidden email]> wrote:
>>
>> 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?
>>
>> _______________________________________________
>> cfe-dev mailing list
>> [hidden email]
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: SemaTemplateInstantiateDecl mistakenly issuing diag::warn_func_template_missing for templated deduction guides

Eric Fiselier via cfe-dev
> The post-commit review thread for this warning concluded that this warning probably shouldn't be on by default, but looks like it didn't get disabled.

Without -Wundefined-func-template, the warning doesn't come up. But even when enabled, does it make sense when the template in question is a deduction guide?

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: SemaTemplateInstantiateDecl mistakenly issuing diag::warn_func_template_missing for templated deduction guides

Eric Fiselier via cfe-dev
In reply to this post by Eric Fiselier via cfe-dev
Hi,

2017-10-25 23:18 GMT+07:00 Aaron Ballman via cfe-dev <[hidden email]>:
On Wed, Oct 25, 2017 at 12:16 PM, Nico Weber via cfe-dev
<[hidden email]> wrote:
> The post-commit review thread for this warning concluded that this warning
> probably shouldn't be on by default, but looks like it didn't get disabled.

 
This warning is off by default, but in this case it was enabled by command line option.
 
We don't usually add off-by-default diagnostics because almost no one
ever enables them, so perhaps the diagnostic should simply be removed
if it's low-value?


The two warnings added in r266719 were intended to assist problem solving in the case of
module builds and they were really helpful.

There are many warnings disabled by default. For instance, '-Wfloat-conversion', which is
useful in some cases.

Thanks,
--Serge


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: SemaTemplateInstantiateDecl mistakenly issuing diag::warn_func_template_missing for templated deduction guides

Eric Fiselier via cfe-dev
In reply to this post by Eric Fiselier via cfe-dev
On 25 October 2017 at 07:33, Mário Feroldi via cfe-dev <[hidden email]> wrote:
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?

Thanks for the report, we shouldn't even be trying to instantiate a definition for a deduction guide in the first place. Fixed in r316820.

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev