This implements the changes discussed in https://ghc.haskell.org/trac/ghc/ticket/7401. To summarize:
When EmptyDataDecls is enabled, GHC now derives same instances it would drive for empty data declarations using standalone deriving.
If EmptyDataDecls is disabled, it fails as it does without this patch.
As also asked by Simon in the trac ticket, I updated the error message. (see .stderr files)
There are some discussion about standard compliance in the trac ticket. Most notably, the standard is saying this:
If the data declaration has no constructors (i.e. when n = 0), then no classes are derivable (i.e. m = 0)
However, Simon says in the trac:
And yes, clause (6) in the deriving appendix explicitly dis-allows deriving( Eq ), but here I think it would be OK for GHC to be a little more generous than the standard. That is, with EmptyDataDecls (or Haskell2010) we'd accept data T deriving( Eq ) whereas H2010 would reject it. But failing to reject is very unlikely to break anyone's code.
This change requires EmptyDataDecls extension, so no diversion from the standard is happening. (I think)
One thing that I don't understand about the standard is this: Types with no constructors are syntactically allowed: https://www.haskell.org/onlinereport/haskell2010/haskellch4.html But they're still rejected by GHC, without extensions. I didn't change anything about that in this patch.
fix Trac #7401 - 3
fix Trac #7401 - adding tests
fix a name in comment
fix Trac #7401 - remove duplication
fix Trac #7401 - fix stderr of an existing file for new error message