public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101222] New: unwanted templated constructor instantiation due to wrong binary operator access
@ 2021-06-26 12:01 vopl at bk dot ru
  2021-08-12 23:43 ` [Bug c++/101222] unwanted templated constructor instantiation due to wrong binary operator access with enums pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: vopl at bk dot ru @ 2021-06-26 12:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101222
           Summary: unwanted templated constructor instantiation due to
                    wrong binary operator access
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vopl at bk dot ru
  Target Milestone: ---

cat main.cpp && echo EOFFFFFF

template<typename T> struct Trap {};

struct Some
{
    template<typename T, int = sizeof(Trap<T>)> Some(T) {}// Trap for T - only
for check if Some<T> was instantiated
};
void operator<(const Some&, const Some&);//wrong instantiatoion of
Some::Some<E> here

enum E{};

int main()
{
    bool b = E{} < E{};// wrong access to "bool operator<(const Some&, const
Some&);"
    return 0;
}

template <> struct Trap<E> {};// now check Trap for E

EOFFFFFF

$ g++ -c main.cpp 
main.cpp:17:20: error: specialization of 'Trap<E>' after instantiation
   17 | template <> struct Trap<E> {};// now check Trap for E
      |                    ^~~~~~~
main.cpp:17:20: error: redefinition of 'struct Trap<E>'
main.cpp:1:29: note: previous definition of 'struct Trap<E>'
    1 | template<typename T> struct Trap {};
      |                             ^~~~

-------------------------------------------------
In these code "void operator<(const Some&, const Some&)" is not a candidate for
overloading for "E{} < E{}", so, it must not be used at all, and as a result,
Some::Some<E> must not be instantiated.

All gcc versions with c++11 standard are affected. Clang and msvc are okay.

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

* [Bug c++/101222] unwanted templated constructor instantiation due to wrong binary operator access with enums
  2021-06-26 12:01 [Bug c++/101222] New: unwanted templated constructor instantiation due to wrong binary operator access vopl at bk dot ru
@ 2021-08-12 23:43 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-12 23:43 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |4.6.3
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-08-12
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note changing E to an int rather than an enum allows this to work.

Confirmed.

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

end of thread, other threads:[~2021-08-12 23:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-26 12:01 [Bug c++/101222] New: unwanted templated constructor instantiation due to wrong binary operator access vopl at bk dot ru
2021-08-12 23:43 ` [Bug c++/101222] unwanted templated constructor instantiation due to wrong binary operator access with enums 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).