llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.97k stars 11.54k forks source link

Incorrect error on operator() being an member in template #28937

Open llvmbot opened 8 years ago

llvmbot commented 8 years ago
Bugzilla Link 28563
Version 3.0
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor

Extended Description

Following class correctly compiles without any error in Clang 3.0:

struct NonTemplate
{
    typedef void type();

    type operator(); //Actually declares an member function.
};

However in case of the class template:

template<typename T>
struct Template
{
    typedef T type;

    T operator();
};

Followinge error is generated:

error: declaration of 'operator()' as non-function
     T operator();

Despite the fact that Template<void()> is identical to NonTemplate.

wheatman commented 7 months ago

This still does not compile with post 18 trunk(d9a9872ec4760762fdc467ef283cea302a3742e5) https://godbolt.org/z/e4doGnv87

It also fails to compile on gcc 13.2 and EDG 6.6 It compiles on msvc 19.38

code

struct NonTemplate
{
    typedef void type();

    type operator(); //Actually declares an member function.
};

template<typename T>
struct Template
{
    typedef T type;

    T operator();
};

clang error

<source>:13:7: error: 'operator()' cannot be the name of a variable or data member
   13 |     T operator();
      |       ^
1 error generated.
Compiler returned: 1

gcc error

<source>:13:7: error: declaration of 'operator()' as non-function
   13 |     T operator();
      |       ^~~~~~~~
Compiler returned: 1

EDG error

"<source>", line 13: error: an operator name must be declared as a function
      T operator();
        ^

1 error detected in the compilation of "<source>".
Compiler returned: 2
llvmbot commented 7 months ago

@llvm/issue-subscribers-clang-frontend

Author: None (llvmbot)

| | | | --- | --- | | Bugzilla Link | [28563](https://llvm.org/bz28563) | | Version | 3.0 | | OS | Linux | | Reporter | LLVM Bugzilla Contributor | | CC | @DougGregor | ## Extended Description Following class correctly compiles without any error in Clang 3.0: struct NonTemplate { typedef void type(); type operator(); //Actually declares an member function. }; However in case of the class template: template<typename T> struct Template { typedef T type; T operator(); }; Followinge error is generated: error: declaration of 'operator()' as non-function T operator(); Despite the fact that Template<void()> is identical to NonTemplate.