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

            Bug ID: 39263
           Summary: Clang wrongly reports duplicate member error on using
                    recursive template
           Product: clang
           Version: 7.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]

I am using Clang 7.0 on Windows 10, but could reproduce the issue on Compiler
Explorer using different compiler versions.

The following code compiles fine on GCC (tested with 4.2 (!) and 4.8 and other
versions available on Compiler Explorer), and on MSVC 19 (again on CE).

But yields error on every clang I tried, both on my local machine as well as on
Compiler Explorer.

The code requires boost (tested with 1.52 and newer)

Code:

```
#include <boost/mpl/integral_c.hpp>

struct r_base {};

typedef long long r_value_t;

template<r_value_t N, r_value_t D = 1>
struct r : r_base
{
    static const r_value_t n = N;
    static const r_value_t d = D;
};

template<r_value_t X>
struct a : boost::mpl::integral_c<r_value_t, (X < 0) ? -X : X> {};

template<r_value_t U, r_value_t V>
struct g : g<V, U % V> {};

template<r_value_t U>
struct g<U, 0> : a<U> {};

template<typename T>
struct r_r
{
    static const r_value_t n = a<T::n>::value;
    static const r_value_t d = a<T::d>::value; // error happens here: d is
duplicate member
    static const r_value_t g = g<n, d>::value;
};

Clang reports the errors:
<source>:29:37: error: duplicate member 'd'

    static const r_value_t g = g<n, d>::value;

                                    ^
<source>:28:28: note: previous declaration is here

    static const r_value_t d = a<T::d>::value;

                           ^
<source>:29:38: error: expected ';' at end of declaration list

    static const r_value_t g = g<n, d>::value;

                                     ^
                                     ;

```

Thank you in advance.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to