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++ accept illegal code #37234

Closed
llvmbot opened this issue Jun 21, 2018 · 1 comment
Closed

clang++ accept illegal code #37234

llvmbot opened this issue Jun 21, 2018 · 1 comment
Labels
bugzilla Issues migrated from bugzilla c++ duplicate Resolved as duplicate

Comments

@llvmbot
Copy link
Member

llvmbot commented Jun 21, 2018

Bugzilla Link 37886
Resolution DUPLICATE
Resolved on Jun 21, 2018 11:25
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@DougGregor,@zygoloid

Extended Description

The code is as follow:

#include

template
struct SimpleAllocator
{
template friend struct SimpleAllocator;

using value_type = T;
using pointer = T *;

struct rebind { template <typename U> using other = SimpleAllocator<U>; };

using propagate_on_container_copy_assignment = std::true_type;
using propagate_on_container_move_assignment = std::true_type;
using propagate_on_container_swap = std::true_type;

explicit SimpleAllocator(void * p) : state(p) {}

template <typename U>
SimpleAllocator(SimpleAllocator<U> const & rhs) : state(rhs.state) {}

pointer allocate(std::size_t n)
{
    return static_cast<pointer>(::operator new(sizeof(T) * n));
}

void deallocate(pointer p, std::size_t)
{
    ::operator delete(p);
}

template <typename U, typename V>
friend bool operator==(SimpleAllocator<U> const & lhs, SimpleAllocator<V> const & rhs)
{
    return lhs.state == rhs.state;
}

template <typename U, typename V>
friend bool operator!=(SimpleAllocator<U> const & lhs, SimpleAllocator<V> const & rhs)
{
    return lhs.state != rhs.state;
}

private:
void * state;
};

using astring = std::basic_string<char, std::char_traits, SimpleAllocator>;

int main()
{
int x, y;

SimpleAllocator<void> a(&x), b(&y);

astring s("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", a);
astring t(std::move(s), b);

}

The code sample comes from #20709
The latest clang compiles the attached code sample, but gcc produces many errors.

I reported the problem to gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86074

In this discussion, programmers indicate that clang shall also reject the code.
My report was marked as duplicated with multiple reports:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78925
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54376

It said that GCC, EDG, and MSVC all reject the code, but clang++ accepts it.

Shall clang repair the problem?

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Jun 21, 2018

*** This bug has been marked as a duplicate of bug llvm/llvm-bugzilla-archive#31507 ***

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
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++ duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

1 participant