public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98524] New: accepts-invalid instantiation of variable template with different function pointer type from declaration
@ 2021-01-05  8:43 adr26__gcc at nunsway dot co.uk
  2021-01-05  8:46 ` [Bug c++/98524] " adr26__gcc at nunsway dot co.uk
  2021-08-17  8:49 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: adr26__gcc at nunsway dot co.uk @ 2021-01-05  8:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98524

            Bug ID: 98524
           Summary: accepts-invalid instantiation of variable template
                    with different function pointer type from declaration
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: adr26__gcc at nunsway dot co.uk
  Target Milestone: ---

Consider:

  template<typename T> void (*TF)(int);
  template void (*TF<int>)(int);

Per [temp.explicit]/6, the above are two declarations of the same entity:

  The declaration in an explicit-instantiation and the declaration produced by
the corresponding substitution into the templated function, variable, or class
are two declarations of the same entity.

  [Note 1: These declarations are required to have matching types as specified
in [basic.link], except as specified in [except.spec].

  [Example 2:
    template<typename T> T var = {};
    template float var<float>;      // OK, instantiated variable has type float
    template int var<int[16]>[];    // OK, absence of major array bound is
permitted
    template int *var<int>;         // error: instantiated variable has type
int

    template<typename T> auto av = T();
    template int av<int>;           // OK, variable with type int can be
redeclared with type auto

    template<typename T> auto f() {}
    template void f<int>();         // error: function with deduced return type
                                    // redeclared with non-deduced return type
([dcl.spec.auto])

  — end example]
  — end note]

http://eel.is/c++draft/temp.explicit#6

and per [basic.link]/11.1, these two declarations of a entity which is a
variable shall declare the variable to be of the same (function pointer) type:

  For any two declarations of an entity E :

    (11.1) If one declares E to be a variable or function, the other shall
declare E as one of the same type.

http://eel.is/c++draft/basic.link#11.1

There isn't a "no diagnostic required" exception for this case in either
[temp.explicit] or [basic.link], and clang and ICC (EDG front end) both
correctly detect this error:

  clang:

  <source>:2:10: error: type 'void (*)(int)' of explicit instantiation of 'TF'
does not match expected type 'void (*)()'
  template void (*TF<int>)(int);
           ^
  <source>:1:29: note: variable template 'TF' declared here
  template<typename T> void (*TF)();
                              ^

  ICC:

  <source>(2): error: declaration is incompatible with "void (*TF)() [with
T=int]" (declared at line 1)
    template void (*TF<int>)(int);
                    ^

https://gcc.godbolt.org/z/qa6395

[NB: MSVC also incorrectly fails to detect this error, and I have reported this
in the context of a separate bug in its handling of variable templates:

https://developercommunity2.visualstudio.com/t/Incorrect-C3410-on-explicit-instantiatio/1301005

where it doesn't handle the correct code:

  template<typename T> void (*TF)(int);
  template void (*TF<int>)(int);

!]

g++ should issue a diagnostic for this, similarly to clang and ICC/EDG.

Thanks, Andrew R

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/98524] accepts-invalid instantiation of variable template with different function pointer type from declaration
  2021-01-05  8:43 [Bug c++/98524] New: accepts-invalid instantiation of variable template with different function pointer type from declaration adr26__gcc at nunsway dot co.uk
@ 2021-01-05  8:46 ` adr26__gcc at nunsway dot co.uk
  2021-08-17  8:49 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: adr26__gcc at nunsway dot co.uk @ 2021-01-05  8:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98524

--- Comment #1 from Andrew Rogers <adr26__gcc at nunsway dot co.uk> ---
Apologies for the fat-fingering when copying in the code which triggers this
condition!

The top of this bug report should read -

Consider:

  template<typename T> void (*TF)();
  template void (*TF<int>)(int);

!!!

Andrew R

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/98524] accepts-invalid instantiation of variable template with different function pointer type from declaration
  2021-01-05  8:43 [Bug c++/98524] New: accepts-invalid instantiation of variable template with different function pointer type from declaration adr26__gcc at nunsway dot co.uk
  2021-01-05  8:46 ` [Bug c++/98524] " adr26__gcc at nunsway dot co.uk
@ 2021-08-17  8:49 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-17  8:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98524

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-08-17
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Yes GCC does not check the argument types or return type at all of the function
pointer type.

  template<typename T> void (*TF)(int);
  template int (*TF<int>)(int);

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-17  8:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05  8:43 [Bug c++/98524] New: accepts-invalid instantiation of variable template with different function pointer type from declaration adr26__gcc at nunsway dot co.uk
2021-01-05  8:46 ` [Bug c++/98524] " adr26__gcc at nunsway dot co.uk
2021-08-17  8:49 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).