gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3 typedef unsigned char uint8_t; void f(uint8_t __restrict__ foo[]) { // no warnings/errors } void f2(unsigned char __restrict__ foo[]) { // doesn't compile:: // test.cc:6: error: ‘__restrict__’ qualifiers cannot be applied to ‘unsigned char’ } The two functions should be equivalent, I think -- both erroring or neither erroring. Verbose details follow. $ gcc -v -save-temps test.cc Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu Thread model: posix gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=i486' /usr/lib/gcc/i486-linux-gnu/4.4.3/cc1plus -E -quiet -v -D_GNU_SOURCE test.cc -D_FORTIFY_SOURCE=2 -mtune=generic -march=i486 -fpch-preprocess -fstack-protector -o test.ii ignoring nonexistent directory "/usr/local/include/i486-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../i486-linux-gnu/include" ignoring nonexistent directory "/usr/include/i486-linux-gnu" #include "..." search starts here: #include <...> search starts here: /usr/include/c++/4.4 /usr/include/c++/4.4/i486-linux-gnu /usr/include/c++/4.4/backward /usr/local/include /usr/lib/gcc/i486-linux-gnu/4.4.3/include /usr/lib/gcc/i486-linux-gnu/4.4.3/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=i486' /usr/lib/gcc/i486-linux-gnu/4.4.3/cc1plus -fpreprocessed test.ii -quiet -dumpbase test.cc -mtune=generic -march=i486 -auxbase test -version -fstack-protector -o test.s GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (i486-linux-gnu) compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (i486-linux-gnu) compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 35224f2c24023afb0a5be7befe8d5f3f test.cc:6: error: ‘__restrict__’ qualifiers cannot be applied to ‘unsigned char’
Confirmed. Both variants are rejected when using the C frontend.
C++ ignores inappropriate cv-qualifications introduced through the use of a typedef or template type parameter: int i; typedef int& IR; IR const ir1 = i; // OK int& const ir2 = i; // error G++ is treating restrict the same way. It's not clear to me that this is the right thing to do, but it's not clear that it's wrong, either.
Created attachment 24715 [details] patch But here's a patch against pre-4.7 to do what you want.
Sorry, I should have linked to the bug that prompted this bug report. http://code.google.com/p/skia/issues/detail?id=63 Briefly, the Skia library (used by Google Chrome and Android) has usage of restrict that Clang complains about. In trying to reduce the problem to a test case, I encountered the below inconsistency in gcc and thought I'd be a good citizen to file a bug. If the Skia code is just wrong by the spec, it's probably not worth changing gcc. The Skia usage of restrict presumably worked on some platform, or they wouldn't have checked it in. But perhaps it was ignored on those platforms anyway. I have asked on the Skia bug for more information. It seems likely to me this bug should be WONTFIXed.
Since clang handles this differently, I think I'll leave it as SUSPENDED for now.