<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/62158>62158</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [C++20][modules] Failure to specialize templated variables
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:modules
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            ChuanqiXu9
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mordante
      </td>
    </tr>
</table>

<pre>
    Tested with `clang version 17.0.0 (++20230414071729+999a8b8ce927-1~exp1~20230414071839.627)`

I originally ran into this issue while working on the `std` module in libc++. There we have tests that specialize `std::enable_borrowed_range` for user defined types. This is a reduced example.

I first suspected this issue had something to do with the `inline namespace __1`, but that seems not to be the case. It would be nice when the fix would be tested with an `inline namespace` too.

Using the following 3 files
header.h
```
namespace lib /*::inline __1*/ {
template <class>
inline constexpr bool test = false;
} // namespace lib
```
lib.cppm
```
module;
#include "header.h"
export module lib;

export namespace lib {
using lib::test;
} // namespace lib
```
main.cpp
```
#ifdef HEADER
#include "header.h"
#else
import lib;
#endif

struct foo {};

template <>
inline constexpr bool lib::test<foo> = true;

static_assert(lib::test<foo>);
```
Building with the following command succeeds
```
clang++-17 -std=c++20 -DHEADER -fsyntax-only main.cpp
```

Building with the following commands
```
clang++-17 -std=c++20 --precompile lib.cppm
clang++-17 -std=c++20 -fsyntax-only -fprebuilt-module-path=. main.cpp
```
fails
```
main.cpp:11:28: error: no member named 'test' in namespace 'lib'
inline constexpr bool lib::test<foo> = true;
 ~~~~~^
1 error generated.

```
A work-around it to specialize the variable inside the namespace like
```
namespace lib {
template <>
inline constexpr bool test<foo> = true;
}
```



</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVk2PozgT_jXOpQQCk_BxyCFpOnrn-mpW2lvL2EXwjrFZ23S69zC_fWWg86WopzXaKCIBUx_PU1WPzZyTR424JZs9ofSpG5n-W_45V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