Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7957 Discussions

Bug regarding precedence of sizeof?

phuclv90
Beginner
708 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
692 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,


0 Kudos
phuclv90
Beginner
684 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

0 Kudos
Viet_H_Intel
Moderator
647 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,


0 Kudos
Reply