This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/81299] New: Spurious "set but not used" warning with constexpr variable


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

            Bug ID: 81299
           Summary: Spurious "set but not used" warning with constexpr
                    variable
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ldionne.2 at gmail dot com
  Target Milestone: ---

The following code triggers a spurious warning on GCC trunk (8.0 ish):

  struct function_t {
      template <typename ...Xs>
      void operator()(Xs&& ...) const { }
  };
  constexpr function_t function{};

  int main() {
      constexpr auto fun = ::function;
      auto call = [=](auto ...x) { fun(x...); };
      call();
  }

The output is:

  prog.cc: In function 'int main()':
  prog.cc:8:20: warning: variable 'fun' set but not used
[-Wunused-but-set-variable]
       constexpr auto fun = ::function;
                      ^~~

Live example: https://godbolt.org/g/jNhNJV

This is an incredibly annoying bug that was also present in GCC 7 and causes
trivial constexpr code to fail to compile (when -Werror is used) :-(.

Sorry for using Godbolt (which does not clearly show the warning message)
instead of Wandbox, but Wandbox's shareable links feature are not working right
now.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]