]> granicus.if.org Git - clang/commit
Add support for attribute enum_extensibility.
authorAkira Hatanaka <ahatanaka@apple.com>
Tue, 21 Mar 2017 02:23:00 +0000 (02:23 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Tue, 21 Mar 2017 02:23:00 +0000 (02:23 +0000)
commit18021952cce94fde55068790887992c1c9e0e2e8
treeda4768b15b3b03e0537c7846cc457b663b838c88
parent5f5f6d1226b8977ca12b009bb82ed983653d4ac3
Add support for attribute enum_extensibility.

This commit adds support for a new attribute that will be used to
distinguish between extensible and inextensible enums. There are three
main purposes of this attribute:

1. Give better control over when enum-related warnings are issued.
For example, in the code below, clang will not issue a -Wassign-enum
warning if the enum is marked "open":

enum __attribute__((enum_extensibility(closed))) EnumClosed {
  B0 = 1, B1 = 10
};

enum __attribute__((enum_extensibility(open))) EnumOpen {
  C0 = 1, C1 = 10
};

enum EnumClosed ec = 100; // warning issued
enum EnumOpen eo = 100; // no warning

2. Enable code-completion and debugging tools to offer better
suggestions.

3. Make it easier for swift's clang importer to determine which swift
type an enum should be mapped to.

For more details, see the discussion I started on cfe-dev:
http://lists.llvm.org/pipermail/cfe-dev/2017-February/052748.html

rdar://problem/12764379
rdar://problem/23145650

Differential Revision: https://reviews.llvm.org/D30766

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298332 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/AST/Decl.h
include/clang/Basic/Attr.td
include/clang/Basic/AttrDocs.td
lib/AST/Decl.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclAttr.cpp
lib/Sema/SemaStmt.cpp
test/Sema/enum-attr.c [new file with mode: 0644]
test/SemaCXX/attr-flag-enum-reject.cpp [deleted file]
test/SemaCXX/enum-attr.cpp [new file with mode: 0644]