Issue 180527
Summary Incorrect template specialization from precompiled header gets used in source file
Labels new issue
Assignees
Reporter eleviant
    When template member function is specialized inside the template class scope and this class definition is in the precompiled header then only first member function template specialization can be used. To reproduce:
```
# build.sh - build script, define LLVM and CLANG_VER variables before use
$LLVM/bin/clang -cc1 -internal-isystem $LLVM/lib/clang/$CLANG_VER/include -nostdsysteminc \
-internal-isystem $LLVM/../clang/test/Headers/Inputs/include -fmodules -x c++-header -emit-pch -o stdafx.pch stdafx.h
$LLVM/bin/clang -cc1 -internal-isystem $LLVM/lib/clang/$CLANG_VER/include -nostdsysteminc -fmodules \
-x c++ -include-pch stdafx.pch main.cpp
```
```
// stdafx.h - precompiled header
#ifndef STDAFX_H
#define STDAFX_H

template <typename T>
class Test {
public:

        template <int I> constexpr int get(T t) const;
 template <> constexpr int get<0>(T t) const { return t + 10; }
 template <> constexpr int get<1>(T t) const { return t + 11; }
};

#endif
```
```
// main.cpp - source file
#include "stdafx.h"

constexpr Test<int> t;
static_assert(t.get<0>(10) == 20);
static_assert(t.get<1>(10) == 21);    // This fails

int main(int argc, char **argv) {
    return 0;
}
```



_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to