ned14 / llfio

P1031 low level file i/o and filesystem library for the C++ standard
https://ned14.github.io/llfio/
Other
880 stars 45 forks source link

Compiler internal error because of min/max defines #126

Closed Andersama closed 1 year ago

Andersama commented 1 year ago

The project suffers the classic min/max define problem. Currently on projects which may have accidentally defined min/max as a macro the compiler can't properly parse the header. It may be worth refactoring std::min and std::max out of the project, alternatively be sure to guard against min and max preprocessor defines.

BurningEnlightenment commented 1 year ago

Thanks for bringing it up. I personally think that it is not worth the effort to implement mitigations for these long-shunned practices. OTOH we could add a preprocessor check which explicitly #errors out if min/max have been redefined.

Andersama commented 1 year ago

I'm just glad that shuffling the include produced different errors which eventually lead me to figure out what lines were a problem, was a pretty strange experience including a library in a test project where it worked and then bringing it elsewhere for it to generate a compiler internal error.

ned14 commented 1 year ago

I assume it was the windows headers which did this? They're the usual culprit.

They can be ordered to not defined min or max using an opt out macro.

Andersama commented 11 months ago

@ned14 Pretty certain you're right that it was the windows headers buried somewhere. A compiler internal error was a first, usually the replacement makes for an obvious error the compiler should pick up on, this was strange. I wish compiler internal errors came with some additional feedback, the only thing we can know for certain is some macro replacement of min/max somewhere threw the compiler for a loop.