0

[I'd really request anyone tagging this as duplicate to read the whole question before hastily marking it as such. My question is why compilers are allowed to interpret this differently, is this an undefined or unspecified or required behavior?]

This is the code

typedef double Money;

class Account {
public:
    Money balance() {
        return bal;
    }
private:
    typedef long Money;
    Money bal;
};

According to C++ Primer 5e, it is an error to redefine the same type (Money) in inner class scope.
However, it's also mentioned that some compilers may not enforce this.

Does that mean it is an undefined behavior, or unspecified behavior? If standard explicitly says that this is not allowed, how can major compilers decide not to flag this as an error?

patentfox
  • 1,436
  • 2
  • 13
  • 28
  • At the bottom of the linked question, it's mentioned that *"Although it is an error to redefine a type name, compilers are not required to diagnose this error."*. I think that refers to the code being 'ill-formed, no diagnostic required' (rather than causing undefined or unspecified behavior). – HolyBlackCat Jun 30 '19 at 14:41
  • I'd really request anyone requesting anyone tagging this as duplicate to read the whole question before hastily marking it as such read the whole question before hastily requesting as such. (OK, joking) Well, this is called "ill-formed, no diagnostic allowed." See http://eel.is/c++draft/intro.compliance#1. – L. F. Jul 02 '19 at 09:06

0 Answers0