public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104509] New: Scoped enum as bit field in a function template
@ 2022-02-12  3:06 vofogi5810 at goonby dot com
  2022-02-12  3:11 ` [Bug c++/104509] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: vofogi5810 at goonby dot com @ 2022-02-12  3:06 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104509
           Summary: Scoped enum as bit field in a function template
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vofogi5810 at goonby dot com
  Target Milestone: ---

The following fails:

#include <cassert>

struct test {
  enum class state { off, on };
  state st: 1; // bit field
  bool is_on() const {
    return st == state::on; // this is ok
  }
  template<bool flag>
  bool is() const {
    if constexpr (flag) return st == state::on; // error?
    else return st == state::off;
  }
};

int main() {
  test t{test::state::on};
  return !t.is<true>();
}

GCC output:

error: no match for ‘operator==’ (operand types are ‘const signed char:1’ and
‘test::state’)

Non-template function works. Current workaround is to apply static_cast.

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

* [Bug c++/104509] Scoped enum as bit field in a function template
  2022-02-12  3:06 [Bug c++/104509] New: Scoped enum as bit field in a function template vofogi5810 at goonby dot com
@ 2022-02-12  3:11 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-12  3:11 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 99804.

*** This bug has been marked as a duplicate of bug 99804 ***

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

end of thread, other threads:[~2022-02-12  3:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-12  3:06 [Bug c++/104509] New: Scoped enum as bit field in a function template vofogi5810 at goonby dot com
2022-02-12  3:11 ` [Bug c++/104509] " 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).