g++ 4.4 および 4.5 で奇妙な問題を発見しました。コードでばかげたエラーを起こしていると思ったので、これについて尋ねました。元の投稿はここにありますが、投稿を完了するために、問題のある問題のあるコードをここに再投稿します。
$ cat templatetemplate.cc
template <int i>
struct LabelTypeMap { typedef int type_t; };
template <bool>
struct Hold { typedef int type; };
template<typename Holder, template<typename Holder::type> class typeMap>
struct Whatever { };
template <bool Enable>
struct Now { typedef Whatever<Hold<ENABLE>, LabelTypeMap> concrete_t; };
Now<true>::concrete_t obj;
$ g++ -DENABLE=Enable -c templatetemplate.cc
templatetemplate.cc:11: error: type/value mismatch at argument 2 in template parameter list for ‘template<class Holder, template<typename Holder::type <anonymous> > class typeMap> struct Whatever’
templatetemplate.cc:11: error: expected a template of type ↵
‘template<typename Holder::type <anonymous> > class typeMap’, got ↵
‘template<int i> struct LabelTypeMap’
marcelo@macbookpro-1:~/play$
$ g++ -DENABLE=true -c templatetemplate.cc
(no error)
これは実際にはプログラマーのエラーではないように思われますが、テンプレートのテンプレート パラメーター解決に関するあいまいなルールが欠落している可能性はあるかもしれません。ただし、バグをubuntuトラッカーに投稿しようとしました(うまくいけば、バグを却下するか、バグを上流に送信します)
それで、これが本当にバグかどうかを確認するためだけに、私は 2003 年標準のコピーを手に入れました。セクション 14.3.3 を数回読みましたが、合格したかどうかのわずかな手がかりを見落としていると感じています。サンプル コードのようなパラメーターを持つテンプレート テンプレート パラメーターは許可または禁止されます。ドキュメントのこの部分がこれについて何か言及しているかどうかさえわかりません
これが私の質問です。これがどこに指定されているか知っていますか?
編集: この質問が 1 週間以上回答されていないことは非常に興味深いことです: 以前のテンプレート パラメーターを使用して後続のテンプレート パラメーターの型を指定できるかどうか (少なくともそれは基本的に実装者の決定に委ねられています
2 番目の編集 (2011 年 10 月 1 日): 人々、これにはおそらく私たち全員が見逃している何かがあります (または、多くの熟練したコンパイラ設計者が間違っています): Intel C++ コンパイラ XE 12.0 でこれを試したところ、次のようになりました:
$icpc ttemplatetemplate.cc -o ./x2test
templatetemplate.cc(12): error: class template "LabelTypeMap" is not compatible with template template parameter "typeMap"
struct Now { typedef Whatever<Hold<Enable>, LabelTypeMap> concrete_t; };
^
compilation aborted for templatetemplate.cc (code 2)
$ icpc --version
icpc (ICC) 12.0.0 20101116
Copyright (C) 1985-2010 Intel Corporation. All rights reserved.