[cfe-users] inserted-name bug?

Jens B. Jorgensen jorgensen at kcg.com
Mon Aug 11 20:05:57 PDT 2014


Compiling the attached sample produces:

clang_inserted_name_bug.cpp:34:45: error: template argument for template
      template parameter must be a class template or type alias template
                typedef TraitChooser_t<TRAITS, BASE_TYPE, TemplClass> Traits;
                                                          ^
clang_inserted_name_bug.cpp:35:55: error: template argument for template
      template parameter must be a class template or type alias template
                typedef BASE_TYPE<TraitChooser_t<TRAITS, BASE_TYPE, Temp...
                                                                    ^
2 errors generated.

I think this is incorrect as even though TemplClass becomes an injected-class-name when used in the template-argument-list where a template parameter goes it should get the template, not the class. Others discuss here:

https://stackoverflow.com/questions/12810630/how-do-i-refer-to-a-class-template-as-a-template-from-within-its-own-class-def

--
Jens B. Jorgensen jorgensen at kcg.com<mailto:jorgensen at kcg.com>
This e-mail and its attachments are intended only for the individual or entity to whom it is addressed and may contain information that is confidential, privileged, inside information, or subject to other restrictions on use or disclosure. Any unauthorized use, dissemination or copying of this transmission or the information in it is prohibited and may be unlawful. If you have received this transmission in error, please notify the sender immediately by return e-mail, and permanently delete or destroy this e-mail, any attachments, and all copies (digital or paper). Unless expressly stated in this e-mail, nothing in this message should be construed as a digital or electronic signature. For additional important disclaimers and disclosures regarding KCG’s products and services, please click on the following link:

http://www.kcg.com/legal/global-disclosures
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20140812/bef3bde1/attachment.html>
-------------- next part --------------
// build with: clang++ -c -std=c++11 clang_inserted_name_bug.cpp

#include <type_traits>
	template <typename TRAITS, typename DERIVEDTYPE>
	struct DerivedTraits : public TRAITS
	{
		typedef DERIVEDTYPE DerivedType;
		static constexpr bool hasDerived() { return true; }
	};


	template <typename TRAITS, template <typename> class DERIVEDTYPE>
	struct TraitChooser
	{
		typedef typename std::conditional<TRAITS::hasDerived(), TRAITS, DerivedTraits<TRAITS, DERIVEDTYPE<TRAITS> > >::type TraitType;
	};


	template<template<typename> class BASE_TYPE, template<typename, template<typename> class> class DERIVED_TEMPLATE>
	struct BaseClassTransformer
	{
		template<typename TRAITS>
		using Result = DERIVED_TEMPLATE<TRAITS, BASE_TYPE>;
	};

	template<
		typename Traits,
		template<typename> class BASE_TYPE,
		template<typename, template<typename> class> class DERIVED_TEMPLATE> using TraitChooser_t = typename TraitChooser<Traits, BaseClassTransformer<BASE_TYPE, DERIVED_TEMPLATE>::template Result>::TraitType;


	template <typename TRAITS, template<typename> class BASE_TYPE>
	class TemplClass : public BASE_TYPE<TraitChooser_t<TRAITS, BASE_TYPE, TemplClass>>
	{
	public:
		typedef TraitChooser_t<TRAITS, BASE_TYPE, TemplClass> Traits;
		typedef BASE_TYPE<TraitChooser_t<TRAITS, BASE_TYPE, TemplClass>> base_t;
	};

	struct Traits
	{
		constexpr static bool hasDerived() { return false; }
	};

	template <typename T>
	class BaseClass
	{
	};
		
void instantiate()
{
	TemplClass<Traits, BaseClass> tc;
}


More information about the cfe-users mailing list