Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.
7768 Discussions

Bug regarding precedence of sizeof?

phuclv90
Beginner
469 Views

While answering this question I realized that ICC got it wrong about precedence of sizeof and []

#include <iostream>

int main() {
std::cout << (sizeof(int)["abcdefghij"]) << '\n';
}

It should be parsed as sizeof((int)["abcdefghij"]) because [] has higher precedence than sizeof which will result in a compilation error. But ICC 21.1.9 does compile it and prints "e" which is "abcdefghij"[sizeof(int)]

Demo on Godbolt

From the above link we can see that other compilers report an error as expected

0 Kudos
3 Replies
Viet_H_Intel
Moderator
453 Views

This seems to be a bug in icpc. icpx does give an error as expected. Will icpx work for you or you would like to see it fixed?

Thanks,


phuclv90
Beginner
445 Views

It isn't important to me since I don't use it for work. Just report it so you guys know that there's a bug

Viet_H_Intel
Moderator
408 Views

I've reported this to our Developer and we will will no longer respond to this thread.  

If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.

Thanks,


Reply