Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang allows forming pointer to function with cv-qualifier-seq or ref-qualifier #20116

Open
llvmbot opened this issue May 14, 2014 · 4 comments
Labels
bugzilla Issues migrated from bugzilla c++11 clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@llvmbot
Copy link
Member

llvmbot commented May 14, 2014

Bugzilla Link 19742
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@zygoloid

Extended Description

When compiling the following code using C++11 options:

-Wall -Wextra -std=c++11 -pedantic 

or using C++1y options:

-Wall -Wextra -std=c++1y -pedantic

it is accepted by clang 3.5 trunk 208701 or 3.4 final:

//---------------------
template<class T>
struct add_ptr 
{
  using type = T*;
};

int main() {
  using FC = void () const;
  using PFC = add_ptr<FC>::type;
  using FLR = void () &;
  using PFLR = add_ptr<FLR>::type;
  using FRR = void () &&;
  using PFRR = add_ptr<FRR>::type;
}
//---------------------

After resolution of CWG 1417,

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1417

the formation of a pointer to function types with cv-qualifier or ref-qualifier (even in template context) is not supported. In non-template context, clang already rejects such an attempt.

The code had been compiled using the online-compiler

http://melpon.org/wandbox/

therefore the provided information about OS and hardware are guesses on my side.

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented May 15, 2014

Fixed in r208825, but I'm leaving this open because we're not done here yet. We still incorrectly accept these:

  template<typename T> struct S {
    void f(T);
  };
  S<void () const> s1;
  S<void () &> s2;

... because we don't properly validate the pointer type we build when performing function-to-pointer decay.

@llvmbot
Copy link
Member Author

llvmbot commented Feb 19, 2016

Fixed in r208825, but I'm leaving this open because we're not done here yet.
We still incorrectly accept these:

template struct S {
void f(T);
};
S<void () const> s1;
S<void () &> s2;

... because we don't properly validate the pointer type we build when
performing function-to-pointer decay.

Good afternoon,

so, in the context of this question I would like to clarify, that this rule (8.3.1/4):

Forming a reference to function type is ill-formed if the function type has cv-qualifiers or a ref-qualifier

applicable for this code:

#include <iostream>

template <typename F>
void (* test()) (F);

template <typename X> 
char (& probe( void(*) ( X * ) ) )[1];

template <typename X> 
char (& probe( void(*) ( X   ) ) )[2];

int main()
{
    std::cout << sizeof(probe(test<void() const>()));
}

in context of C++14 standard (for versions 3.4 and earlier this code prints 1, 3.5 and higher prints 2)?

And what about C++03 (in which there is no explicit limitation)? Behaviour whould same, or not?

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
@Endilll Endilll changed the title clang allows forming pointer to function with cv-qualifier-seq or ref-qualifier clang allows forming pointer to function with cv-qualifier-seq or ref-qualifier Jul 27, 2024
@Endilll Endilll added the clang:to-be-triaged Should not be used for new issues label Jul 27, 2024
@frederick-vs-ja
Copy link
Contributor

And what about C++03 (in which there is no explicit limitation)? Behaviour whould same, or not?

The explicit limitation was added by DR CWG1417, so the behavior should be same in old modes.

@frederick-vs-ja frederick-vs-ja added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed clang:to-be-triaged Should not be used for new issues labels Dec 31, 2024
@llvmbot
Copy link
Member Author

llvmbot commented Dec 31, 2024

@llvm/issue-subscribers-clang-frontend

Author: None (llvmbot)

| | | | --- | --- | | Bugzilla Link | [19742](https://llvm.org/bz19742) | | Version | trunk | | OS | Linux | | Reporter | LLVM Bugzilla Contributor | | CC | @DougGregor,@zygoloid |

Extended Description

When compiling the following code using C++11 options:

-Wall -Wextra -std=c++11 -pedantic 

or using C++1y options:

-Wall -Wextra -std=c++1y -pedantic

it is accepted by clang 3.5 trunk 208701 or 3.4 final:

//---------------------
template&lt;class T&gt;
struct add_ptr 
{
  using type = T*;
};

int main() {
  using FC = void () const;
  using PFC = add_ptr&lt;FC&gt;::type;
  using FLR = void () &amp;;
  using PFLR = add_ptr&lt;FLR&gt;::type;
  using FRR = void () &amp;&amp;;
  using PFRR = add_ptr&lt;FRR&gt;::type;
}
//---------------------

After resolution of CWG 1417,

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1417

the formation of a pointer to function types with cv-qualifier or ref-qualifier (even in template context) is not supported. In non-template context, clang already rejects such an attempt.

The code had been compiled using the online-compiler

http://melpon.org/wandbox/

therefore the provided information about OS and hardware are guesses on my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++11 clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

3 participants