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

    <tr>
        <th>Summary</th>
        <td>
            [C++20] [Modules] Confusing error message about invisible namespace
        </td>
    </tr>

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

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

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

<pre>
    I got this issue report in a private chat and I think it is better to track it.

The reproducer:

```
// tm.cppm
module;
#include <vector>
export module tm;

export void mf();

// tc.cpp
import tm;

int main()
{
 std::printf("main\n");
    mf();
}
```

then when we compile `tc.cpp`, we'll see the error message like:

```
tc.cpp:16:5: error: missing '#include <vector>'; 'std' must be declared before it is used
   16 | std::printf("main\n");
      | ^
/usr/lib/gcc/x86_64-redhat-linux/9/../../../../include/c++/9/vector:104:11: note: declaration here is not visible
  104 | namespace std _GLIBCXX_VISIBILITY(default)
      |           ^
tc.cpp:16:10: error: no member named 'printf' in namespace 'std'
   16 | std::printf("main\n");
      |     ~~~~~^
2 errors generated.
```

The issue reporter's opinion is that, the header `vector` in the error message is confusing since there is nothing about `<vector>`.

The reason for the issue is that, in the diagnostic handler, we don't handle namespace decl specially. So that we will show the first declaration and say it is invisible to imply the users to export that. But it is confusing for namespace decl since it smells not good for users to export a whole namespace.

Also, once a declaration in the namespace got exported, the namespace become visible too. So the solution in my mind may be, we can  simply don't diagnose anything if the declaration is a namespace declaration. Then the showed error message will be:

```
tc.cpp:16:10: error: no member named 'printf' in namespace 'std'
   16 |     std::printf("main\n");
      |     ~~~~~^
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVk-P46gT_TTkUuoI49huH3JI0pOfIs3vNKPV7GmEoRKzgyELuDO57Gdfgcm_ntmRRmrLojtAFa_eqyrDvVcHg7gk1ZowtulHbv5WX8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