更新: ここでコードを修正したので、すぐにプラグインしてコンパイルを試みることができます。
Clang 3.4.1 (LLVM 3.4) は、可変引数関数で使用された場合、私のクラスが POD 型ではない (私が知る限り、これは確実にそうである) と不平を言います。G++ はこれをコンパイルしても問題ありません。
このクラスは、C++03 の標準でも POD です。
- メンバーとしてPODSのみが含まれています
- ユーザー定義のデストラクタがない
- ユーザー定義のコピー代入演算子がありません
- メンバーへのポインター型の非静的メンバーはありません
また、「POD」とは何かに関する C++11 の規則が緩和されたので、ここで何が起こっているのでしょうか?
コードについて: これは (ベクター グラフィックスのような) ベクターのテンプレート クラスであり、可変個引数関数は配列に任意のデータを入力するために使用されます。
私のクラスヘッダーファイル:
template<typename TYPE>
class Vec3t;
typedef Vec3t<float> Vec3f;
template<typename TYPE>
class Vec3t {
public:
Vec3t<TYPE>( void ){}
Vec3t<TYPE>( const TYPE nx, const TYPE ny, const TYPE nz ){}
Vec3t<TYPE> operator-(void) const{}
Vec3t<TYPE> operator*( const Vec3t<TYPE> &other ) const{}
Vec3t<TYPE> operator*( const TYPE val ) const{}
Vec3t<TYPE>& operator*=( const Vec3t<TYPE> &other ){}
Vec3t<TYPE>& operator*=( const TYPE val ){}
Vec3t<TYPE> operator+( const Vec3t<TYPE> &other ) const{}
Vec3t<TYPE> operator+( const TYPE val ) const{}
Vec3t<TYPE>& operator+=( const Vec3t<TYPE> &other ){}
Vec3t<TYPE>& operator+=( const TYPE val ){}
Vec3t<TYPE> operator-( const Vec3t<TYPE> &other ) const{}
Vec3t<TYPE> operator-( const TYPE val ) const{}
Vec3t<TYPE>& operator-=( const Vec3t<TYPE> &other ){}
Vec3t<TYPE>& operator-=( const TYPE val ){}
Vec3t<TYPE> operator/( const Vec3t<TYPE> &other ) const{}
Vec3t<TYPE> operator/( const TYPE val ) const{}
Vec3t<TYPE>& operator/=( const TYPE val ){}
Vec3t<TYPE>& operator/=( const Vec3t<TYPE> &other ){}
bool operator==( const Vec3t<TYPE> &b ) const {}
bool operator==( const TYPE b ) const {}
bool operator!=( const Vec3t<TYPE> &b ) const {}
bool operator!=( const TYPE b ) const {}
Vec3t<TYPE>& Set( const TYPE a, const TYPE b, const TYPE c ){}
Vec3t<TYPE>& Set( const TYPE a, const TYPE b ){}
void Cross( const Vec3t<TYPE> &other, Vec3t<TYPE> &out ) const{}
TYPE Dot( const Vec3t<TYPE> &other ) const{}
Vec3t<TYPE> PerpCCW_ZAxis( void ){}
Vec3t<TYPE> PerpCW_ZAxis( void ){}
float Len( void ) const{}
void Zero( void ){}
static void Cross( const Vec3t<TYPE> &other, const Vec3t<TYPE> &u, Vec3t<TYPE> &out ){}
Vec3f Normalize( void ){}
Vec3f Rotation( TYPE angle ){}
float DegreesBetween( const Vec3f &other ){}
float RadiansBetween( const Vec3f &other ){}
Vec3f Rotate( float angle, const bool inRadians = false ){}
static float Len( const Vec3f &other ){}
public:
TYPE x,y,z;
};
template< typename TYPE >
void FillArray( const std::size_t count, TYPE* var, ... ) {
va_list vargs;
va_start( vargs, var );
for ( std::size_t i=0; i<count; i++ ) {
var[i] = va_arg( vargs, TYPE ); // ** THIS IS THE LINE CLANG ERRS ON ** //
}
va_end( vargs );
}
私の可変長関数ヘッダーファイル:
#include <cstdarg>
template< typename TYPE >
void FillArray( const std::size_t count, TYPE* var, ... ) {
va_list vargs;
va_start( vargs, var );
for ( std::size_t i=0; i<count; i++ ) {
var[i] = va_arg( vargs, TYPE ); // ** THIS IS THE LINE CLANG ERRS ON ** //
}
va_end( vargs );
}
Clang のエラー: エラー: 'va_arg' の 2 番目の引数は非 POD タイプ 'Vec3t' です [-Wnon-pod-varargs]
これらを使用して Clang でエラーを引き起こすプログラム例: #include "fillarray.h"
int main ( void ) {
Vec3t<float> v[2];
FillArray< Vec3t<float> >( 2, v, 0.4f, 0.5f);
}
コンパイル: clang++ x.cpp -I/usr/include/i386-linux-gnu/c++/4.8 -std=gnu++11