g++ has an inaccuracy when following the C++03 standard concerning the equality of types with different linkage. Section 7.5.1 states that: "Two function types with different language linkages are distinct types even if they are otherwise identical.".
Then the following code snippet should not compile:
extern "C" void (*const interruptVectors)();
typedef void (*ISR_t)(void);
static ISR_t* source_vector_table = const_cast<ISR_t*>(interruptVectors);
Although interruptVectors is of type const ISR_t* it has C linkage, thus the types should be different and the const_cast should not work.
I have discovered this behavior when compiling a code base with TI's ARM compiler which choked on the aforementioned snippet. A TI employee then referred me to the C++03 standard (https://e2e.ti.com/support/development_tools/compiler/f/343/t/654558), which seems to back the compiler's behavior.
See PR2316. Don't hold your breath for a change, it is more likely that the standard will eventually be changed to allow the current behavior.
Well I don't mind the current behavior at all and to be honest I find it more logical that way, so I would welcome a change in the standard.
Should I then close this bugreport or keep it open for further reference?
It's a duplicate of PR 2316.
*** This bug has been marked as a duplicate of bug 2316 ***