[llvm-bugs] [Bug 42354] New: declaring a function with a computed typedef is confused as a data member by definition

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jun 21 09:24:51 PDT 2019


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

            Bug ID: 42354
           Summary: declaring a function with a computed typedef is
                    confused as a data member by definition
           Product: clang
           Version: 8.0
          Hardware: Macintosh
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: alisdairm at me.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Note that this bug is a real corner case unlikely to occur in production code,
but bit us in experimental coding.

The following program should compile equivalently, regardless of the definition
of the SHOW_BUG macro:

#include <type_traits>

#define SHOW_ERROR 1

using namespace std;

template <typename T>
struct why_me {

#if defined(SHOW_ERROR)
   using what_the = conditional_t<is_const_v<T>, void() noexcept, void()>;
#else
   using what_the = void() noexcept(is_const_v<T>);
#endif

   what_the heck;
};

template <typename T>
void why_me<T>::heck() noexcept(is_const_v<T>) {}

int main() {
   why_me<int> x = {};
   x.heck();

   why_me<int> y = {};
   y.heck();
}


However, when SHOW_BUG is defined, we get the following errors:

to_heck_with_it.cpp:20:17: error: redefinition of 'heck' as different kind of
symbol
void why_me<T>::heck() noexcept(is_const_v<T>) {}
                ^
to_heck_with_it.cpp:16:13: note: previous definition is here
   what_the heck;
            ^
to_heck_with_it.cpp:16:13: error: data member instantiated with function type
'why_me<int>::what_the' (aka 'void ()')
   what_the heck;
            ^
to_heck_with_it.cpp:23:16: note: in instantiation of template class
'why_me<int>' requested here
   why_me<int> x = {};
               ^
2 errors generated.



The program compiles and runs as expected when SHOW_BUG is not defined.

-- 
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/20190621/97ab386c/attachment.html>


More information about the llvm-bugs mailing list