Wrong template syntax or gcc is buggy?

Mar 31, 2012 at 6:02pm
In line 23, I get a:
internal compiler error: tree check: expected tree that contains 'decl minimal' structure, have 'nop_expr' in decl_linkage, at cp/tree.c:3136


I have wrong syntax, or I must report a gcc bug? (really?!!!)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
typedef cl_int (*cfi)(void*, cl_uint, size_t, void*, size_t*);

template<class T>
T getInfo(cfi func, void *obj, cl_uint name)
{
	T tmp { T() };
	cl_int status = func(obj, name, sizeof(tmp), &tmp, 0);
	if (status == CL_SUCCESS || status == CL_INVALID_VALUE) return tmp;
	else throw Exception(status);
}

template <class Holder, class Info, cfi Func>
struct StructureInfo
{
	Holder operator*() const { return data; }
	template<class T>
	T getInfo(Info name) const { return getInfo<T>(Func, data, name); }

protected:
	Holder data;	//!< Real OpenCL encapsulated structure.
};

struct Platform : public StructureInfo<cl_platform_id, cl_platform_info, (cfi) clGetPlatformInfo>
{
...
Mar 31, 2012 at 6:12pm
Could you substitute for built_in types your types and show an example that everyone can copy it and compile?
Mar 31, 2012 at 6:31pm
Exactly why are you casting clGetPlatformInfo?
But regardless of whether the code is correct or not, an internal compiler error is always a bug and must be reported.
Mar 31, 2012 at 6:41pm
Are you using the latest version of your compiler?
Mar 31, 2012 at 7:08pm
Sorry pals.
There is a bug report already in gcc bug tracker.
A simplified program works fine, instead.
I will fix it with a workaround.
Apr 1, 2012 at 2:28pm
This is a plain C++ simplified code.
gcc 4.7.0 has a bug for sure. But is the code correct anyway?
1
2
3
4
5
6
7
8
9
10
11
12
typedef void (*cfi)(void*);

void function(int *a) {}

template<cfi Func>
void *get() { Func(0);  }

int main()
{
	get<(cfi) function>();
	return 0;
}

------>g++ -std=c++11 1.cpp
1.cpp: In function 'int main()':
1.cpp:10:22: internal compiler error: tree check: expected tree that contains 'd
ecl minimal' structure, have 'nop_expr' in decl_linkage, at cp/tree.c:3136
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Apr 1, 2012 at 2:41pm
> But is the code correct anyway?

No.

1
2
template<cfi Func>
void *get() { Func(0);  } // error: no return statement in function returning non-void 


And, AFAIK, using the result of this reinterpret_cast leads to undefined behaviour: (cfi) function

But GCC 4.7 has this bug alright.
Last edited on Apr 1, 2012 at 2:51pm
Apr 1, 2012 at 3:14pm
Yeap, I forget to remove asterisk.
1
2
template<cfi Func>
void get() { Func(0);  }

But why leads to undefined behavior?

what is the difference (in CPU opcodes) between:
1
2
void (*)(void*) // and
void (*)(int*)
Last edited on Apr 1, 2012 at 3:17pm
Apr 2, 2012 at 7:35am
> But why leads to undefined behavior?
> what is the difference (in CPU opcodes) between: ...

'Undefined behaviour' means 'behavior for which the International Standard imposes no requirements' - just that and nothing more.

Permissible 'undefined behaviour' includes "behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message)".

It is easy to see why the IS states: The effect of calling a function through a pointer to a function type that is not the same as the type used in the definition of the function is undefined.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// There is nothing in foo() that leads to undefined behaviour
void foo( int* pi ) { if(pi) ++*pi ; }

typedef void fn_type( double* ) ;

// There is also nothing in bar() that leads to undefined behaviour
double bar( fn_type* pfn )
{
   double d = 8.9 ;
   pfn(&d) ;
   return d ;
}

// But the code in main() results in aliasing that leads to undefined behaviour
int main()
{
    std::cout << foo( reinterpret_cast<fn_type*>( &func ) ) ;
}



Topic archived. No new replies allowed.