[llvm-bugs] [Bug 42630] New: -Wunused-const-variable inconsistent with constexpr

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jul 16 03:01:24 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=42630

            Bug ID: 42630
           Summary: -Wunused-const-variable inconsistent with constexpr
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jvapen at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

When looking at the -Wunused-const-variable warning, we discovered that the
reporting of this warning is not consistent.

In the example below, we get a warning if:
 - inline constexpr in unnamed namespace
 - constexpr in unnamed namespace
 - constexpr in global namespace
However, we don't get the warning for:
 - inline constexpr in global namespace

=> From a programmers point of view, all 4 cases are the same -> constexpr
variable that ain't being used.

Example with warning:
https://godbolt.org/z/BWTmKA 

// Clang++ -std=c++17 -Werror -Wunused-const-variable 
#include <type_traits>

namespace
{
 // Dependent false_type
   template<typename T>
   struct dependent_false : std::false_type {};

   template<typename T>
   inline constexpr bool dependent_false_v = dependent_false<T>::value;

   template<typename T>
   auto func(T &&t) -> int
      {
      using TDeduce = std::decay_t<decltype(t)>;
      if constexpr(true)
         {
         return 1;
         }
      else
         {
         static_assert(dependent_false_v<TDeduce>, "wrong types");
         return 0;
         }
      }
}

int main()
{
    return func(5);
}



=> Remove unnamed namespace to suppress the warning.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190716/a5423138/attachment-0001.html>


More information about the llvm-bugs mailing list