[llvm-bugs] [Bug 39169] New: Incorrect accessibility check when using decltype inside class definition

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Oct 3 16:21:03 PDT 2018


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

            Bug ID: 39169
           Summary: Incorrect accessibility check when using decltype
                    inside class definition
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: romain.geissler at amadeus.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

Hi,

The following snippet will current result in an error with all clang versions
(including trunk):

<<EOF
#include <type_traits>

class A
{
    private:
        static std::true_type F(int);

        static std::false_type F(...);

    public:
        template <typename T> using F_t = decltype(F(std::declval<T>()));

    static_assert(A::F_t<int>::value, ""); // OK
};

static_assert(A::F_t<int>::value, ""); // KO
EOF



The error happens on the second static_assert made outside the class
definition:

<source>:11:52: error: 'F' is a private member of 'A'

        template <typename T> using F_t = decltype(F(std::declval<T>()));

                                                   ^

<source>:16:18: note: in instantiation of template type alias 'F_t' requested
here

static_assert(A::F_t<int>::value, ""); // KO

                 ^

<source>:6:31: note: declared private here

        static std::true_type F(int);

                              ^

1 error generated.

Compiler returned: 1


Given that the "decltype()" expression is used inside the class itself, I would
consider that it is OK to access private members from there, thus using the
public "F_t" from outside the class should be OK.

gcc compiles this without error.

Cheers,
Romain

-- 
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/20181003/1be15e99/attachment.html>


More information about the llvm-bugs mailing list