Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
For the latest information on Intel’s response to the Log4j/Log4Shell vulnerability, please see Intel-SA-00646

Bug regarding precedence of sizeof?

phuclv90
Beginner
282 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
266 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
258 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
221 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