#include <stdio.h> char str[] = "abc";
const char *a1 = str; struct A { operator const char *() {return str;} } a2; volatile char *b1 = str; struct B { operator volatile char *() {return str;} } b2; int main() { printf ("%p\n", a1); printf ("%p\n", b1); printf ("%p\n", (const char *)a2); printf ("%p\n", (volatile char *)b2); printf ("%d\n", a1 - b1); printf ("%d\n", (const char *)a2 - (volatile char *)b2); printf ("%d\n", a2 - b2); // error reported here return 0; } gives: t.cpp: In function int main(): t.cpp:22: error: no match for operator- in a2 - b2 t.cpp:22: note: candidates are: operator-(volatile char*, volatile char*) <built-in> t.cpp:22: note: operator-(const char*, const char*) <built-in> However, lines 20 and 21 clearly do the same operation, but slightly differently. These lines appear to be able to convert the types, presumably according to clause 4.4 of the C++ standard, but the last example cannot. Yet the error message shows that it has found the right conversion operators. EDG 3.0 compiles this without any issues. Note: the correct behaviour of this program is to print the same pointer four times, and then print zero three times. -- Summary: can't subtract 'volatile char *' from 'const char *' Product: gcc Version: 4.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: andrew dot stubbs at st dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29148