llvm / llvm-project

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

Clang fails to detect dependent parameters in function scoped classes #115815

Open ojhunt opened 1 week ago

ojhunt commented 1 week ago

Was writing test cases and found that clang fails to diagnose destroying operator delete with dependent parameters in function scoped class definitions:

template <typename T> void test_func() {
    struct __attribute__((aligned(128))) MyTerribleThing {
    MyTerribleThing(){};
    void *operator new(size_t, T) throw() {return 0;}
    void operator delete(void *, T){}
    void operator delete(MyTerribleThing *, std::destroying_delete_t, T){}
    };
    auto *obj = new MyTerribleThing;
    delete obj;
}

int main() {
 test_func<std::align_val_t>();
 return 0;
}

gcc rejects, clang accepts. Both incorrectly (by my reading of the spec) accept this with the destroying delete removed, and emit an aligned delete.

llvmbot commented 1 week ago

@llvm/issue-subscribers-clang-frontend

Author: Oliver Hunt (ojhunt)

Was writing test cases and found that clang fails to diagnose destroying operator delete with dependent parameters in function scoped class definitions: ```cpp template <typename T> void test_func() { struct __attribute__((aligned(128))) MyTerribleThing { MyTerribleThing(){}; void *operator new(size_t, T) throw() {return 0;} void operator delete(void *, T){} void operator delete(MyTerribleThing *, std::destroying_delete_t, T){} }; auto *obj = new MyTerribleThing; delete obj; } int main() { test_func<std::align_val_t>(); return 0; } ``` gcc rejects, clang accepts. Both incorrectly (by my reading of the spec) accept this with the destroying delete removed, and emit an aligned delete.