A better example is when you have a #FF0000 red background. WCAG says you should use #000000 black text on it, but #FFFFFF white text is actually more accessible to people with color deficient vision[1] and, to my eyes at least, reads more easily and has more contrast.
Please don’t use a #FF0000 background under any circumstance.
It is an extremely colorful medium-lightness red which will be somewhere between unpleasant and physically uncomfortable to look at (not to mention illegible) irrespective of the foreground text color.
[1] https://accessibility.psu.edu/color/colorvisiondetails/#RK