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

            Bug ID: 118751
           Summary: optional diagnostic not given on invalid bitfield
                    reference in uninstantiated template
           Product: gcc
           Version: 14.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: matoro_gcc_bugzilla at matoro dot tk
  Target Milestone: ---

Sample comparison:  https://godbolt.org/z/3zYfe35jM

gcc does not diagnose non-const bitfield references in uninstantiated
templates, while clang does.

#include <utility>

template <typename T>
struct s
{
    int m : 5;
    void swap()
    {
        std::swap(m, m);
    }
};

clang:

<source>:9:19: error: non-const reference cannot bind to bit-field 'm'
    9 |         std::swap(m, m);
      |                   ^
<source>:6:9: note: bit-field is declared here
    6 |     int m : 5;
      |         ^
/opt/compiler-explorer/gcc-14.2.0/lib/gcc/x86_64-linux-gnu/14.2.0/../../../../include/c++/14.2.0/bits/move.h:213:15:
note: passing argument to parameter '__a' here
  213 |     swap(_Tp& __a, _Tp& __b)
      |               ^

gcc does correctly diagnose if template is instantiated.  This is technically
optional so it's not a correctness issue but gcc's lack of even a warning here
is giving the impression that clang is doing something wrong.

Reply via email to