[llvm-bugs] [Bug 38631] New: Clang refuses to compile code that other compilers do due to __restrict

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Aug 18 20:53:09 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38631

            Bug ID: 38631
           Summary: Clang refuses to compile code that other compilers do
                    due to __restrict
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: dark_sylinc at yahoo.com.ar
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

I wasn't sure to call this a "bug" because __restrict keyword is supposedly a
compiler extension, so portability is not guaranteed.

However Clang is the only compiler (vs MSVC and GCC) to refuse to build this
simple snippet of code and seems to me this behavior is not really
intended/expected from Clang:

struct Obj
{
    float * __restrict myPtr[2];
};

int main()
{
    Obj a, b;

    a = b;

    return 0;
}

The error is:
main.cpp:742:8: error: cannot initialize a parameter of type 'void *' with an
rvalue of type 'float *__restrict (*)[2]'
struct Obj
       ^~~
../../src/main.cpp:751:7: note: in implicit copy assignment operator for 'Obj'
first required here
    a = b;

Removing the __restrict keyword fixes the problem. Also another way to fix the
problem is to split myPtr[2] into two variables, e.g. myPtr0 and myPtr1

Using __restrict__ instead of __restrict yields the same outcome.

Invocation is:
clang++-6.0 -Wall -Wextra -g -DDEBUG -MD -MT
CMakeFiles/Playground.dir/src/main.cpp.o -MF
CMakeFiles/Playground.dir/src/main.cpp.o.d -o
CMakeFiles/Playground.dir/src/main.cpp.o -c ../../src/main.cpp

clang++-6.0 --version
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180819/e5f22e9c/attachment.html>


More information about the llvm-bugs mailing list