Are #include " <> " and #include < "" > valid file inclusions?

Viewed 180

This is nitpicky, probably without any practical use. I am just curious...

From the C++20 working draft (n4861), header names are defined as:

(5.8)
header-name:
    < h-char-sequence >
    " q-char-sequence "
h-char-sequence :
    h-char
    h-char-sequence h-char
h-char:
    any member of the source character set except new-line and >
q-char-sequence :
    q-char
    q-char-sequence q-char
q-char:
    any member of the source character set except new-line and "

where the "source character set" is defined as:

(5.3.1) The basic source character set consists of 96 characters: the space character, the control characters representing
horizontal tab, vertical tab, form feed, and new-line, plus the following 91 graphical characters:9
  a b c d e f g h i j k l m n o p q r s t u v w x y z
  A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  0 1 2 3 4 5 6 7 8 9
  _ { } [ ] # ( ) < > % : ; . ? * + - / ^ & | ~ ! = , \ " ’

and Source file inclusions are defined as:

(15.3.2) A preprocessing directive of the form
    # include < h-char-sequence > new-line
    ...

(15.3.3) A preprocessing directive of the form
    # include " q-char-sequence " new-line
    ...

As I understand it, this means that the both include directives #include " <> " and #include < "" > are perfectly valid, one following the h-char-sequence, the other following the q-char-sequence.

This however seems rather strange and bizarre to me. I tried creating a header file named <> in visual studio which (IMHO kind of sanely) forbid this, informing me that no such header file may be created as both chars < and > are forbidden.

Strictly speaking, is visual studio following the Standard in this regard or am I overlooking something? Are both header names valid or invalid? If invalid, which section of the standard forbids this? Also, as the definitions of source file inclusions contain a space, is #include <iostream> even valid?

1 Answers

Slightly further down, you'll find text similar to the below (taken from the C99 standard):

The implementation shall provide unique mappings for sequences consisting of one or more letters or digits (as defined in 5.2.1) followed by a period (.) and a single letter. The first character shall be a letter. The implementation may ignore the distinctions of alphabetical case and restrict the mapping to eight significant characters before the period.

This has been unchanged pretty much since C99 and probably before. So an implementation is allowed to reject include directive with odd characters in the file name (such as " or <), but is not required to.

Related