XL C/C++ コンパイラーを V8.0 から V10.1 にアップグレードしていますが、V8.0 でコンパイルされているにもかかわらず、エラーが発生するコードが見つかりました。最小限の例を次に示します。
test.h:
#include <iostream>
#include <string>
template <class T>
void f()
{
std::cout << TEST << std::endl;
}
test.cpp:
#include <string>
#include "test.h"
namespace
{
std::string TEST = "test";
}
int main()
{
f<int>();
return 0;
}
V10.1 では、次のエラーが発生します。
"test.h", line 7.16: 1540-0274 (S) The name lookup for "TEST" did not find a declaration.
"test.cpp", line 6.15: 1540-1303 (I) "std::string TEST" is not visible.
"test.h", line 5.6: 1540-0700 (I) The previous message was produced while processing "f<int>()".
"test.cpp", line 11.3: 1540-0700 (I) The previous message was produced while processing "main()".
g++ 3.3.2 と 4.3.2 の間にも同様の違いが見つかりました。g ++でも見つけまし#include "test.h"た。名前のない名前空間宣言の後に移動すると、コンパイルエラーがなくなります。
ここで私の質問です。標準はこれについて何と言っていますか? テンプレートがインスタンス化されるとき、そのインスタンスは、テンプレート自体が宣言された時点で宣言されていると見なされますか?それとも、この時点で標準はそれほど明確ではありませんか? n2461.pdf のドラフトを調べてみましたが、決定的なものは何も思いつきませんでした。