├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── pull_request_template.md └── workflows │ └── ci.yml ├── .gitignore ├── Cargo.toml ├── LICENSE ├── README.md ├── TODO.md ├── binding.gyp ├── bindings ├── node │ ├── binding.cc │ └── index.js └── rust │ ├── build.rs │ └── lib.rs ├── examples ├── SemaObjC.sh ├── SemaObjC │ ├── ClassPropertyNotObject.m │ ├── ContClassPropertyLookup.m │ ├── DoubleMethod.m │ ├── Inputs │ │ ├── arc-system-header.h │ │ ├── empty.h │ │ ├── module.map │ │ └── non-trivial-c-union.h │ ├── NSString-type.m │ ├── aarch64-sve-types.m │ ├── access-property-getter.m │ ├── alias-test-1.m │ ├── alias-test-2.m │ ├── arc-bridged-cast.m │ ├── arc-cf.m │ ├── arc-decls.m │ ├── arc-dict-bridged-cast.m │ ├── arc-invalid.m │ ├── arc-jump-block.m │ ├── arc-no-runtime.m │ ├── arc-non-pod-memaccess.m │ ├── arc-nsconsumed-errors.m │ ├── arc-objc-lifetime-conflict.m │ ├── arc-objc-lifetime.m │ ├── arc-objcbridge-related-attribute.m │ ├── arc-peformselector.m │ ├── arc-property-decl-attrs.m │ ├── arc-property-lifetime.m │ ├── arc-property.m │ ├── arc-readonly-property-ivar-1.m │ ├── arc-readonly-property-ivar.m │ ├── arc-repeated-weak.mm │ ├── arc-setter-property-match.m │ ├── arc-system-header.m │ ├── arc-type-conversion.m │ ├── arc-unavailable-for-weakref.m │ ├── arc-unavailable-system-function.m │ ├── arc-unbridged-cast.m │ ├── arc-unsafe-assigns.m │ ├── arc-unsafe_unretained.m │ ├── arc.m │ ├── argument-checking.m │ ├── assign-rvalue-message.m │ ├── at-defs.m │ ├── atomic-property-synthesis-rules.m │ ├── attr-availability-1.m │ ├── attr-availability-priority.m │ ├── attr-availability.m │ ├── attr-called-once.m │ ├── attr-cf_returns.m │ ├── attr-cleanup.m │ ├── attr-deprecated-pch.m │ ├── attr-deprecated-replacement-fixit.m │ ├── attr-deprecated.m │ ├── attr-designated-init.m │ ├── attr-malloc.m │ ├── attr-nodebug.m │ ├── attr-ns_returns_retained.m │ ├── attr-objc-exception.m │ ├── attr-objc-gc.m │ ├── attr-objc-non-lazy.m │ ├── attr-objc-runtime-visible.m │ ├── attr-print.m │ ├── attr-root-class.m │ ├── attr-swift-async-error.m │ ├── attr-swift-async.m │ ├── attr-swift-error.m │ ├── attr-swift_bridge.m │ ├── attr-swift_bridged_typedef.m │ ├── attr-swift_name.m │ ├── attr-swift_newtype.m │ ├── attr-swift_objc_members.m │ ├── attr-swift_private.m │ ├── autoreleasepool.m │ ├── avoid-unavailable-implementation-warning-in-app-extension.m │ ├── bad-property-synthesis-crash.m │ ├── bad-receiver-1.m │ ├── block-as-object.m │ ├── block-attr.m │ ├── block-compare.mm │ ├── block-explicit-return-type.m │ ├── block-id-as-block-argtype.m │ ├── block-ivar.m │ ├── block-literal-with-attribute.m │ ├── block-omitted-return-type.m │ ├── block-on-method-param.m │ ├── block-return.m │ ├── block-type-safety.m │ ├── blocks.m │ ├── boxing-illegal.m │ ├── builtin_objc_assign_ivar.m │ ├── builtin_objc_lib_functions.m │ ├── builtin_objc_msgSend.m │ ├── builtin_objc_nslog.m │ ├── call-super-2.m │ ├── call-unavailable-init-in-self.m │ ├── catch-invalid.m │ ├── catch-stmt.m │ ├── category-1.m │ ├── category-direct-members-protocol-conformance.m │ ├── category-direct-properties.m │ ├── category-method-lookup-2.m │ ├── category-method-lookup.m │ ├── check-dup-decl-methods-1.m │ ├── check-dup-objc-decls-1.m │ ├── check-objcbridge-related-attribute-lookup.m │ ├── circular-container.m │ ├── class-bitfield.m │ ├── class-conforming-protocol-1.m │ ├── class-conforming-protocol-2.m │ ├── class-def-test-1.m │ ├── class-extension-after-implementation.m │ ├── class-extension-dup-methods.m │ ├── class-getter-using-dotsyntax.m │ ├── class-impl-1.m │ ├── class-message-protocol-lookup.m │ ├── class-method-lookup.m │ ├── class-method-self.m │ ├── class-property-access.m │ ├── class-proto-1.m │ ├── class-protocol-method-match.m │ ├── class-protocol.m │ ├── class-stub-attr-unsupported.m │ ├── class-stub-attr.m │ ├── class-unavail-warning.m │ ├── cocoa-api-usage.m │ ├── cocoa-api-usage.m.fixed │ ├── compare-qualified-class.m │ ├── compare-qualified-id.m │ ├── compatible-protocol-qualified-types.m │ ├── compound-init.m │ ├── comptypes-1.m │ ├── comptypes-10.m │ ├── comptypes-2.m │ ├── comptypes-3.m │ ├── comptypes-4.m │ ├── comptypes-5.m │ ├── comptypes-6.m │ ├── comptypes-7.m │ ├── comptypes-8.m │ ├── comptypes-9.m │ ├── comptypes-a.m │ ├── comptypes-legal.m │ ├── conditional-expr-2.m │ ├── conditional-expr-3.m │ ├── conditional-expr-4.m │ ├── conditional-expr-5.m │ ├── conditional-expr-6.m │ ├── conditional-expr-7.m │ ├── conditional-expr-8.m │ ├── conditional-expr.m │ ├── conflict-atomic-property.m │ ├── conflict-nonfragile-abi2.m │ ├── conflicting-ivar-test-1.m │ ├── continuation-class-err.m │ ├── continuation-class-property.m │ ├── conversion.m │ ├── crash-label.m │ ├── crash-on-objc-bool-literal.m │ ├── crash-on-type-args-protocols.m │ ├── custom-atomic-property.m │ ├── dealloc.m │ ├── debugger-cast-result-to-id.m │ ├── debugger-support.m │ ├── default-synthesize-1.m │ ├── default-synthesize-2.m │ ├── default-synthesize-3.m │ ├── default-synthesize-sourceloc.m │ ├── default-synthesize.m │ ├── delay-parsing-cfunctions.m │ ├── deprecate_function_containers.m │ ├── deprecated-objc-introspection.m │ ├── deref-interface.m │ ├── diagnose_if.m │ ├── dictionary-literal-duplicates.m │ ├── direct-synthesized-ivar-access.m │ ├── dist-object-modifiers.m │ ├── dllexport.m │ ├── dllimport.m │ ├── duplicate-ivar-check.m │ ├── duplicate-ivar-in-class-extension.m │ ├── duplicate-property-class-extension.m │ ├── duplicate-property.m │ ├── dynamic-direct-properties.m │ ├── encode-typeof-test.m │ ├── enhanced-proto-2.m │ ├── enum-fixed-type.m │ ├── err-ivar-access-in-class-method.m │ ├── error-implicit-property.m │ ├── error-missing-getter.m │ ├── error-outof-scope-property-use.m │ ├── error-property-gc-attr.m │ ├── exprs.m │ ├── externally-retained-no-arc.m │ ├── externally-retained.m │ ├── flexible-array-arc.m │ ├── flexible-array.m │ ├── foreach.m │ ├── format-arg-attribute.m │ ├── format-cstrings-warning.m │ ├── format-ostrace-warning.m │ ├── format-size-spec-nsinteger.m │ ├── format-strings-objc.m │ ├── format-strings-oslog.m │ ├── format-strings-system.h │ ├── format-strings-utf8.m │ ├── forward-class-1.m │ ├── forward-class-receiver.m │ ├── forward-class-redeclare.m │ ├── forward-protocol-incomplete-impl-warn.m │ ├── gc-attributes.m │ ├── gcc-cast-ext.m │ ├── generic-selection.m │ ├── getter-setter-defined-in-category-of-parent.m │ ├── ibaction.m │ ├── iboutlet.m │ ├── iboutletcollection-attr.m │ ├── id.m │ ├── id_builtin.m │ ├── idiomatic-parentheses.m │ ├── ignore-qualifier-on-qualified-id.m │ ├── ignore-weakimport-method.m │ ├── illegal-nonarc-bridged-cast.m │ ├── incompatible-protocol-qualified-types.m │ ├── incomplete-implementation.m │ ├── infer-availability-from-init.m │ ├── inst-method-lookup-in-root.m │ ├── instancetype.m │ ├── integer-overflow.m │ ├── interface-1.m │ ├── interface-layout-2.m │ ├── interface-layout.m │ ├── interface-scope-2.m │ ├── interface-scope.m │ ├── interface-tu-variable.m │ ├── invalid-code.m │ ├── invalid-objc-decls-1.m │ ├── invalid-receiver.m │ ├── invalid-typename.m │ ├── ivar-access-package.m │ ├── ivar-access-tests.m │ ├── ivar-in-class-extension-error.m │ ├── ivar-in-class-extension.m │ ├── ivar-in-implementations.m │ ├── ivar-lookup-resolution-builtin.m │ ├── ivar-lookup.m │ ├── ivar-ref-misuse.m │ ├── ivar-sem-check-1.m │ ├── ivar-sem-check-2.m │ ├── kindof.m │ ├── legacy-implementation-1.m │ ├── matrix-type-builtins.m │ ├── matrix-type-operators.m │ ├── message.m │ ├── method-arg-qualifier-warning.m │ ├── method-attributes.m │ ├── method-bad-param.m │ ├── method-conflict-1.m │ ├── method-conflict-2.m │ ├── method-conflict.m │ ├── method-def-1.m │ ├── method-def-2.m │ ├── method-direct-arc.m │ ├── method-direct-one-definition.m │ ├── method-direct-properties.m │ ├── method-direct.m │ ├── method-encoding-2.m │ ├── method-in-class-extension-impl.m │ ├── method-lookup-2.m │ ├── method-lookup-3.m │ ├── method-lookup-4.m │ ├── method-lookup-5.m │ ├── method-lookup.m │ ├── method-no-context.m │ ├── method-not-defined.m │ ├── method-prototype-scope.m │ ├── method-redecls-invalid-interface.m │ ├── method-return-void.m │ ├── method-sentinel-attr.m │ ├── method-typecheck-1.m │ ├── method-typecheck-2.m │ ├── method-typecheck-3.m │ ├── method-undef-category-warn-1.m │ ├── method-undef-extension-warn-1.m │ ├── method-undefined-warn-1.m │ ├── method-unused-attribute.m │ ├── method-warn-unused-attribute.m │ ├── mismatched-undefined-method.m │ ├── missing-atend-metadata.m │ ├── missing-method-context.m │ ├── missing-method-return-type.m │ ├── mrc-no-weak.m │ ├── mrc-weak.m │ ├── multiple-method-names-in-class-self.m │ ├── multiple-method-names.m │ ├── multiple-property-deprecated-decl.m │ ├── narrow-property-type-in-cont-class.m │ ├── nested-typedef-decl.m │ ├── newproperty-class-method-1.m │ ├── no-gc-weak-test.m │ ├── no-ivar-access-control.m │ ├── no-ivar-in-interface-block.m │ ├── no-objc-exceptions.m │ ├── no-protocol-option-tests.m │ ├── no-warn-qual-mismatch.m │ ├── no-warn-synth-protocol-meth.m │ ├── no-warn-unimpl-method.m │ ├── no-warning-unavail-unimp.m │ ├── non-trivial-c-union.m │ ├── nonnull.h │ ├── nonnull.m │ ├── nowarn-superclass-method-mismatch.m │ ├── ns-consumed-error-not-warning.m │ ├── ns_returns_retained_block_return.m │ ├── nsobject-attribute-1.m │ ├── nsobject-attribute.m │ ├── nullability-arc.m │ ├── nullability.m │ ├── nullability_macro.m │ ├── nullable-result.m │ ├── nullable-weak-property.m │ ├── objc-array-literal.m │ ├── objc-asm-attribute-neg-test.m │ ├── objc-boxed-expressions-nsvalue.m │ ├── objc-buffered-methods.m │ ├── objc-cf-audited-warning.m │ ├── objc-class-property.m │ ├── objc-container-subscripting-1.m │ ├── objc-container-subscripting-2.m │ ├── objc-container-subscripting-3.m │ ├── objc-container-subscripting-attr.m │ ├── objc-container-subscripting.m │ ├── objc-cstyle-args-in-methods.m │ ├── objc-dictionary-literal.m │ ├── objc-independent-class-attribute.m │ ├── objc-literal-comparison.m │ ├── objc-literal-fixit.m │ ├── objc-literal-nsnumber.m │ ├── objc-literal-sig.m │ ├── objc-mixed-bridge-attribute.m │ ├── objc-qualified-property-lookup.m │ ├── objc-string-constant.m │ ├── objc2-merge-gc-attribue-decl.m │ ├── objc2-warn-weak-decl.m │ ├── objcbridge-attribute-arc.m │ ├── objcbridge-attribute.m │ ├── objcbridge-related-attribute.m │ ├── objcbridgemutable-attribute.m │ ├── opaque-is-access-warn.m │ ├── opaque-is-access.m │ ├── override-nullability.m │ ├── overriding-property-in-class-extension.m │ ├── ovl-check.m │ ├── parameterized_classes.m │ ├── parameterized_classes_arc.m │ ├── parameterized_classes_collection_literal.m │ ├── parameterized_classes_subst.m │ ├── pedantic-dynamic-test.m │ ├── potentially-direct-selector.m │ ├── pragma-pack.m │ ├── property-10.m │ ├── property-11.m │ ├── property-12.m │ ├── property-13.m │ ├── property-2.m │ ├── property-3.m │ ├── property-4.m │ ├── property-5.m │ ├── property-6.m │ ├── property-7.m │ ├── property-8.m │ ├── property-9-impl-method.m │ ├── property-9.m │ ├── property-ambiguous-synthesis.m │ ├── property-and-class-extension.m │ ├── property-and-ivar-use.m │ ├── property-assign-on-object-type.m │ ├── property-atomic-redecl.m │ ├── property-category-1.m │ ├── property-category-2.m │ ├── property-category-3.m │ ├── property-category-4.m │ ├── property-category-impl.m │ ├── property-choose-expr.m │ ├── property-deprecated-warning.m │ ├── property-dot-receiver.m │ ├── property-error-readonly-assign.m │ ├── property-expression-error.m │ ├── property-impl-misuse.m │ ├── property-implement-readonly-with-custom-setter.m │ ├── property-in-class-extension-1.m │ ├── property-in-class-extension.m │ ├── property-inherited.m │ ├── property-ivar-mismatch.m │ ├── property-lookup-in-id.m │ ├── property-method-lookup-impl.m │ ├── property-missing.m │ ├── property-nonfragile-abi.m │ ├── property-noninherited-availability-attr.m │ ├── property-noprotocol-warning.m │ ├── property-not-lvalue.m │ ├── property-ns-returns-not-retained-attr.m │ ├── property-ownership-attr.m │ ├── property-redundant-decl-accessor.m │ ├── property-typecheck-1.m │ ├── property-user-setter.m │ ├── property-weak.m │ ├── property.m │ ├── props-on-prots.m │ ├── protocol-archane.m │ ├── protocol-attribute.m │ ├── protocol-expr-1.m │ ├── protocol-expr-neg-1.m │ ├── protocol-id-test-1.m │ ├── protocol-id-test-2.m │ ├── protocol-id-test-3.m │ ├── protocol-implementation-inherited.m │ ├── protocol-implementing-class-methods.m │ ├── protocol-lookup-2.m │ ├── protocol-lookup.m │ ├── protocol-qualified-class-unsupported.m │ ├── protocol-typecheck.m │ ├── protocol-warn.m │ ├── protocols-suppress-conformance.m │ ├── protocols.m │ ├── provisional-ivar-lookup.m │ ├── qualified-protocol-method-conflicts.m │ ├── rdar6248119.m │ ├── rdr-6211479-array-property.m │ ├── receiver-forward-class.m │ ├── related-result-type-inference.m │ ├── resolve-method-in-global-pool.m │ ├── restrict-id-type.m │ ├── return.m │ ├── scope-check.m │ ├── selector-1.m │ ├── selector-2.m │ ├── selector-3.m │ ├── selector-4.m │ ├── selector-error.m │ ├── selector-overload.m │ ├── self-assign.m │ ├── self-comparison.m │ ├── self-declared-in-block.m │ ├── self-in-function.m │ ├── setter-dotsyntax.m │ ├── severe-syntax-error.m │ ├── sign-conversion.m │ ├── signed-char-bool-conversion.m │ ├── sizeof-interface.m │ ├── special-dep-unavail-warning.m │ ├── stand-alone-implementation.m │ ├── static-ivar-ref-1.m │ ├── stmts.m │ ├── string.m │ ├── strong-in-c-struct.m │ ├── subclassing-restricted-attr.m │ ├── super-cat-prot.m │ ├── super-class-protocol-conformance.m │ ├── super-dealloc-attribute.m │ ├── super-property-message-expr.m │ ├── super-property-notation.m │ ├── super.m │ ├── suspicious-pragma-pack.m │ ├── synchronized.m │ ├── synth-provisional-ivars-1.m │ ├── synth-provisional-ivars.m │ ├── synthesize-setter-contclass.m │ ├── synthesized-ivar.m │ ├── tentative-property-decl.m │ ├── transfer-boxed-string-nullability.m │ ├── transparent-union.m │ ├── try-catch.m │ ├── typedef-class.m │ ├── typo-correction-arc.m │ ├── typo-correction-subscript.m │ ├── typo-correction.m │ ├── ucn-objc-string.m │ ├── undeclared-selector.m │ ├── undef-arg-super-method-call.m │ ├── undef-class-messagin-error.m │ ├── undef-class-property-error.m │ ├── undef-protocol-methods-1.m │ ├── undef-superclass-1.m │ ├── undefined-protocol-type-1.m │ ├── unguarded-availability-category-protocol-use.m │ ├── unguarded-availability-new.m │ ├── unguarded-availability.m │ ├── unimplemented-protocol-prop.m │ ├── uninit-variables.m │ ├── unknown-anytype.m │ ├── unqualified-to-qualified-class-warn.m │ ├── unsafe-perform-selector.m │ ├── unused-backing-ivar-warning.m │ ├── unused.m │ ├── va-method-1.m │ ├── validate-attr-swift_attr.m │ ├── variable-size-ivar.m │ ├── warn-assign-property-nscopying.m │ ├── warn-called-once.m │ ├── warn-cast-of-sel-expr.m │ ├── warn-category-method-deprecated.m │ ├── warn-deprecated-implementations.m │ ├── warn-direct-ivar-access.m │ ├── warn-explicit-call-initialize.m │ ├── warn-forward-class-attr-deprecated.m │ ├── warn-implicit-atomic-property.m │ ├── warn-incompatible-builtin-types.m │ ├── warn-loop-analysis.m │ ├── warn-messaging-id.mm │ ├── warn-missing-super.m │ ├── warn-nontrivial-struct-memaccess.m │ ├── warn-protocol-method-deprecated.m │ ├── warn-retain-block-property.m │ ├── warn-retain-cycle.m │ ├── warn-selector-selection.m │ ├── warn-strict-selector-match.m │ ├── warn-superclass-method-mismatch.m │ ├── warn-thread-safety-analysis.m │ ├── warn-unreachable.m │ ├── warn-unused-exception-param.m │ ├── warn-weak-field.m │ ├── warn-write-strings.m │ ├── warning-missing-selector-name.m │ ├── weak-attr-ivar.m │ ├── weak-property.m │ ├── writable-property-in-superclass.m │ └── x86-method-vector-values.m ├── corpus.m └── corpus.sh ├── grammar.js ├── package.json ├── queries └── highlights.scm ├── src ├── grammar.json ├── node-types.json ├── parser.c └── tree_sitter │ └── parser.h └── test ├── corpus ├── blocks.txt ├── compiler_attributes.txt ├── declarations.txt ├── directives.txt ├── expressions.txt ├── extras.txt ├── github.txt ├── ifdef.txt ├── imports.txt ├── macros.txt ├── properties.txt ├── qualifiers.txt ├── statements.txt ├── typedef.txt └── types.txt └── highlight ├── blocks.txt.m ├── compiler_attributes.txt.m ├── declarations.txt.m ├── directives.txt.m ├── expressions.txt.m ├── extras.txt.m ├── github.txt.m ├── ifdef.txt.m ├── imports.txt.m ├── macros.txt.m ├── properties.txt.m ├── qualifiers.txt.m ├── statements.txt.m ├── typedef.txt.m └── types.txt.m /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Report unexpected parsing results 4 | title: '' 5 | labels: 'bug' 6 | assignees: '' 7 | 8 | --- 9 | 10 | The following piece of code is valid but it is parsed incorrectly: 11 | 12 | ```javascript 13 | 14 | ``` 15 | 16 | Here's a link to the TypeScript Playground showing that the snippet above is valid JavaScript or TypeScript: 17 | 19 | 20 | 21 | The output of `tree-sitter parse` is the following: 22 | 23 | ``` 24 | 25 | ``` 26 | 27 | 29 | 30 | 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 14 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Checklist: 4 | - [ ] All tests pass in CI. 5 | - [ ] There are sufficient tests for the new fix/feature. 6 | - [ ] Grammar rules have not been renamed unless absolutely necessary. 7 | - [ ] The conflicts section hasn't grown too much. 8 | - [ ] The parser size hasn't grown too much (check the value of STATE_COUNT in src/parser.c). 9 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | workflow_dispatch: 4 | pull_request: 5 | push: 6 | 7 | jobs: 8 | test: 9 | runs-on: ${{ matrix.os }} 10 | strategy: 11 | fail-fast: true 12 | matrix: 13 | os: [macos-latest, ubuntu-latest] 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: actions/setup-node@v2 17 | with: 18 | node-version: 14 19 | - run: npm install 20 | - run: npm test -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | *.log 3 | npm-debug.log* 4 | 5 | # Dependency directories 6 | node_modules/ 7 | package-lock.json 8 | 9 | # Builds 10 | build/ 11 | 12 | # Tests 13 | examples/SemaObjC*.txt 14 | 15 | # wasm 16 | *.wasm 17 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "tree-sitter-objc" 3 | description = "Objective-C grammar for the tree-sitter parsing library" 4 | version = "1.0.0" 5 | authors = ["Jiyee Sheng "] 6 | license = "MIT" 7 | keywords = ["tree-sitter", "incremental", "parsing", "objc"] 8 | categories = ["parsing", "text-editors"] 9 | repository = "https://github.com/jiyee/tree-sitter-objc" 10 | edition = "2021" 11 | 12 | build = "bindings/rust/build.rs" 13 | include = [ 14 | "bindings/rust/*", 15 | "grammar.js", 16 | "queries/*", 17 | "src/*", 18 | ] 19 | 20 | [lib] 21 | path = "bindings/rust/lib.rs" 22 | 23 | [dependencies] 24 | tree-sitter = "0.20.6" 25 | 26 | [build-dependencies] 27 | cc = "1.0" 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2022 Jiyee Sheng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | tree-sitter-objc 2 | ======================= 3 | 4 | [![CI Status](https://github.com/jiyee/tree-sitter-objc/actions/workflows/ci.yml/badge.svg)](https://github.com/jiyee/tree-sitter-objc/actions/workflows/ci.yml) 5 | 6 | Objective-C grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter). 7 | 8 | ## References 9 | * [Objective-C Language Reference](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html) - The full grammar reference for Objective-C. 10 | * [LLVM Objective-C Test Cases](https://github.com/llvm-mirror/clang/tree/master/test/CodeGenObjC) - The full test cases for Objective-C. -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | # TODO 2 | [ ] precedence order 3 | [ ] highlights tests 4 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "tree_sitter_objc_binding", 5 | "include_dirs": [ 6 | " 3 | #include "nan.h" 4 | 5 | using namespace v8; 6 | 7 | extern "C" TSLanguage * tree_sitter_objc(); 8 | 9 | namespace { 10 | 11 | NAN_METHOD(New) {} 12 | 13 | void Init(Local exports, Local module) { 14 | Local tpl = Nan::New(New); 15 | tpl->SetClassName(Nan::New("Language").ToLocalChecked()); 16 | tpl->InstanceTemplate()->SetInternalFieldCount(1); 17 | 18 | Local constructor = Nan::GetFunction(tpl).ToLocalChecked(); 19 | Local instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); 20 | Nan::SetInternalFieldPointer(instance, 0, tree_sitter_objc()); 21 | 22 | Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("objc").ToLocalChecked()); 23 | Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); 24 | } 25 | 26 | NODE_MODULE(tree_sitter_objc_binding, Init) 27 | 28 | } // namespace 29 | -------------------------------------------------------------------------------- /bindings/node/index.js: -------------------------------------------------------------------------------- 1 | try { 2 | module.exports = require("../../build/Release/tree_sitter_objc_binding"); 3 | } catch (error1) { 4 | if (error1.code !== 'MODULE_NOT_FOUND') { 5 | throw error1; 6 | } 7 | try { 8 | module.exports = require("../../build/Debug/tree_sitter_objc_binding"); 9 | } catch (error2) { 10 | if (error2.code !== 'MODULE_NOT_FOUND') { 11 | throw error2; 12 | } 13 | throw error1 14 | } 15 | } 16 | 17 | try { 18 | module.exports.nodeTypeInfo = require("../../src/node-types.json"); 19 | } catch (_) {} 20 | -------------------------------------------------------------------------------- /examples/SemaObjC.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BASE_DIR=$(git rev-parse --show-toplevel) 4 | TMP_DIR=$(mktemp -d) 5 | 6 | fd -e h -e m . "${BASE_DIR}/examples/SemaObjC" -x tree-sitter parse {} --quiet | perl -pe 's/\d+ ms\s+\((ERROR|MISSING [^\[]+) \[(\d+),.*$/$2/' | perl -pe 's/\.(h|m)\s*(\d+)/.$1:$2/' > "${TMP_DIR}/temp.txt" 7 | cat "${TMP_DIR}/temp.txt" | awk -F ":" '{print "echo \"###########\" && echo \"" $0 "\" && echo \"\" && "}' > "${TMP_DIR}/echo.txt" 8 | cat "${TMP_DIR}/temp.txt" | awk -F ":" '{print $2}' | xargs -I {} sh -c 'seq -s"," `echo "{}-1" | bc` 2 `echo "{}+1" | bc` && echo ""' | perl -pe 's/,$/p/' | perl -pe "s/^/sed -n '/" | perl -pe "s/$/' /" | perl -pe "s/-1,/0,/" > "${TMP_DIR}/sed.txt" 9 | cat "${TMP_DIR}/temp.txt" | awk -F ":" '{print $1}' > "${TMP_DIR}/file.txt" 10 | paste "${TMP_DIR}/sed.txt" "${TMP_DIR}/file.txt" > "${TMP_DIR}/sed-file.txt" 11 | paste "${TMP_DIR}/echo.txt" "${TMP_DIR}/sed-file.txt" > "${TMP_DIR}/run.sh" 12 | sh "${TMP_DIR}/run.sh" > "${BASE_DIR}/examples/SemaObjC.txt" -------------------------------------------------------------------------------- /examples/SemaObjC/ClassPropertyNotObject.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s 3 | // expected-no-diagnostics 4 | // rdar://10565506 5 | 6 | @protocol P @end 7 | 8 | @interface I 9 | @property Class

MyClass; 10 | @property Class MyClass1; 11 | @property void * VOIDSTAR; 12 | @end 13 | 14 | @implementation I 15 | @synthesize MyClass, MyClass1, VOIDSTAR; 16 | @end 17 | -------------------------------------------------------------------------------- /examples/SemaObjC/ContClassPropertyLookup.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | 4 | @interface MyObject { 5 | int _foo; 6 | } 7 | @end 8 | 9 | @interface MyObject(whatever) 10 | @property (assign) int foo; 11 | @end 12 | 13 | @interface MyObject() 14 | @property (assign) int foo; 15 | @end 16 | 17 | @implementation MyObject 18 | @synthesize foo = _foo; 19 | @end 20 | 21 | // rdar://10666594 22 | @interface MPMediaItem 23 | @end 24 | 25 | @class MPMediaItem; 26 | 27 | @interface MPMediaItem () 28 | @property (nonatomic, readonly) id title; 29 | @end 30 | 31 | @interface PodcastEpisodesViewController 32 | @end 33 | 34 | @implementation PodcastEpisodesViewController 35 | - (id) Meth { 36 | MPMediaItem *episode; 37 | return episode.title; 38 | } 39 | @end 40 | -------------------------------------------------------------------------------- /examples/SemaObjC/DoubleMethod.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -Wduplicate-method-match -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | @interface Subclass 4 | { 5 | int ivar; 6 | } 7 | 8 | - (void) method; // expected-note {{previous declaration is here}} 9 | - (void) method; // expected-warning {{multiple declarations of method 'method' found and ignored}} 10 | @end 11 | 12 | @implementation Subclass 13 | - (void) method {;} // expected-note {{previous declaration is here}} 14 | - (void) method {;} // expected-error {{duplicate declaration of method 'method'}} 15 | @end 16 | 17 | int main (void) { 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /examples/SemaObjC/Inputs/arc-system-header.h: -------------------------------------------------------------------------------- 1 | static inline void *test0(id x) { 2 | return x; 3 | } 4 | 5 | static inline void **test1(__strong id* x) { 6 | return (void**) x; 7 | } 8 | 9 | 10 | 11 | 12 | 13 | struct Test3 { 14 | id *field; 15 | }; 16 | 17 | @interface Test4 { 18 | @public 19 | id *field1; 20 | __strong id *field2; 21 | } 22 | @end 23 | 24 | struct Test5 { 25 | id field; 26 | }; 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | extern struct Test6 *const kMagicConstant; 35 | 36 | 37 | 38 | 39 | 40 | @interface Test7 41 | @property id *prop; 42 | @end 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | static inline void *test8(id ptr) { 51 | return (__bridge_retain void*) ptr; 52 | } 53 | 54 | typedef struct { 55 | const char *name; 56 | id field; 57 | } Test9; 58 | -------------------------------------------------------------------------------- /examples/SemaObjC/Inputs/empty.h: -------------------------------------------------------------------------------- 1 | struct S { int x; }; 2 | -------------------------------------------------------------------------------- /examples/SemaObjC/Inputs/module.map: -------------------------------------------------------------------------------- 1 | module empty { 2 | header "empty.h" 3 | } 4 | -------------------------------------------------------------------------------- /examples/SemaObjC/Inputs/non-trivial-c-union.h: -------------------------------------------------------------------------------- 1 | // For backward compatibility, fields of C unions declared in system headers 2 | // that have non-trivial ObjC ownership qualifications are marked as unavailable 3 | // unless the qualifier is explicit and __strong. 4 | 5 | #pragma clang system_header 6 | 7 | typedef __strong id StrongID; 8 | 9 | typedef union { 10 | id f0; 11 | _Nonnull id f1; 12 | __weak id f2; 13 | StrongID f3; 14 | } U0_SystemHeader; 15 | 16 | typedef union { // expected-note {{'U1_SystemHeader' has subobjects that are non-trivial to destruct}} expected-note {{'U1_SystemHeader' has subobjects that are non-trivial to copy}} 17 | __strong id f0; // expected-note {{f0 has type '__strong id' that is non-trivial to destruct}} expected-note {{f0 has type '__strong id' that is non-trivial to copy}} 18 | _Nonnull id f1; 19 | } U1_SystemHeader; 20 | -------------------------------------------------------------------------------- /examples/SemaObjC/NSString-type.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fblocks -fsyntax-only -verify %s 2 | // rdar://10907410 3 | 4 | void test(id pid, Class pclass) { 5 | void (^block)(void) = @"help"; // expected-error {{initializing 'void (^)(void)' with an expression of incompatible type 'NSString *'}} 6 | void (^block1)(void) = pid; 7 | void (^block2)(void) = @"help"; // expected-error {{initializing 'void (^)(void)' with an expression of incompatible type 'NSString *'}} 8 | void (^block3)(void) = @"help"; // expected-error {{initializing 'void (^)(void)' with an expression of incompatible type 'NSString *'}} 9 | } 10 | 11 | -------------------------------------------------------------------------------- /examples/SemaObjC/access-property-getter.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify %s 2 | 3 | @protocol Protocol 4 | - (oneway void) method; 5 | @end 6 | 7 | void accessMethodViaPropertySyntaxAndTriggerWarning(id object) { 8 | object.method; // expected-warning {{property access result unused - getters should not be used for side effects}} 9 | } 10 | 11 | // rdar://19137815 12 | #pragma clang diagnostic ignored "-Wunused-getter-return-value" 13 | 14 | void accessMethodViaPropertySyntaxWhenWarningIsIgnoredDoesNotTriggerWarning(id object) { 15 | object.method; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /examples/SemaObjC/alias-test-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @compatibility_alias alias4 foo; // expected-warning {{cannot find interface declaration for 'foo'}} 4 | 5 | @class class2; // expected-note {{previous declaration is here}} 6 | @class class3; 7 | 8 | typedef int I; // expected-note {{previous declaration is here}} 9 | 10 | @compatibility_alias alias1 I; // expected-warning {{cannot find interface declaration for 'I'}} 11 | 12 | @compatibility_alias alias class2; 13 | @compatibility_alias alias class3; // expected-error {{conflicting types for alias 'alias'}} 14 | 15 | 16 | typedef int alias2; // expected-note {{previous declaration is here}} 17 | @compatibility_alias alias2 class3; // expected-error {{conflicting types for alias 'alias2'}} 18 | 19 | alias *p; 20 | class2 *p2; 21 | 22 | int foo () 23 | { 24 | 25 | if (p == p2) { 26 | int alias = 1; 27 | } 28 | 29 | alias *p3; 30 | return p3 == p2; 31 | } 32 | -------------------------------------------------------------------------------- /examples/SemaObjC/alias-test-2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | // Note: GCC doesn't produce any of the following errors. 4 | @interface Super @end // expected-note {{previous definition is here}} 5 | 6 | @interface MyWpModule @end // expected-note {{previous definition is here}} 7 | 8 | @compatibility_alias MyAlias MyWpModule; 9 | 10 | @compatibility_alias AliasForSuper Super; 11 | 12 | @implementation MyAlias : AliasForSuper // expected-error {{conflicting super class name 'Super'}} 13 | @end 14 | 15 | @interface MyAlias : AliasForSuper // expected-error {{duplicate interface definition for class 'MyWpModule'}} 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /examples/SemaObjC/arc-no-runtime.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fobjc-arc -verify -Wno-objc-root-class %s 2 | 3 | // rdar://problem/9150784 4 | void test(void) { 5 | __weak id x; // expected-error {{cannot create __weak reference because the current deployment target does not support weak references}} 6 | __weak void *v; // expected-warning {{'__weak' only applies to Objective-C object or block pointer types}} 7 | } 8 | 9 | @interface A 10 | @property (weak) id testObjectWeakProperty; // expected-note {{declared here}} 11 | @end 12 | 13 | @implementation A 14 | // rdar://9605088 15 | @synthesize testObjectWeakProperty; // expected-error {{cannot synthesize weak property because the current deployment target does not support weak references}} 16 | @end 17 | -------------------------------------------------------------------------------- /examples/SemaObjC/arc-readonly-property-ivar-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fobjc-arc -fsyntax-only -verify -Wno-objc-root-class %s 2 | // RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fobjc-arc -fsyntax-only -verify -Wno-objc-root-class %s 3 | // expected-no-diagnostics 4 | // rdar:// 10558871 5 | 6 | @interface PP 7 | @property (readonly) id ReadOnlyPropertyNoBackingIvar; 8 | @property (readonly) id ReadOnlyProperty; 9 | @property (readonly) id ReadOnlyPropertyX; 10 | @end 11 | 12 | @implementation PP { 13 | __weak id _ReadOnlyProperty; 14 | } 15 | @synthesize ReadOnlyPropertyNoBackingIvar; 16 | @synthesize ReadOnlyProperty = _ReadOnlyProperty; 17 | @synthesize ReadOnlyPropertyX = _ReadOnlyPropertyX; 18 | @end 19 | 20 | @interface DD 21 | @property (readonly) id ReadOnlyProperty; 22 | @property (readonly) id ReadOnlyPropertyStrong; 23 | @property (readonly) id ReadOnlyPropertyNoBackingIvar; 24 | @end 25 | 26 | @implementation DD { 27 | __weak id _ReadOnlyProperty; 28 | __strong id _ReadOnlyPropertyStrong; 29 | } 30 | @end 31 | -------------------------------------------------------------------------------- /examples/SemaObjC/arc-readonly-property-ivar.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fobjc-arc -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | // rdar:// 10558871 4 | 5 | @interface PP 6 | @property (readonly) id ReadOnlyPropertyNoBackingIvar; 7 | @property (readonly) id ReadOnlyProperty; 8 | @property (readonly) id ReadOnlyPropertyX; 9 | @end 10 | 11 | @implementation PP { 12 | __weak id _ReadOnlyProperty; 13 | } 14 | @synthesize ReadOnlyPropertyNoBackingIvar; 15 | @synthesize ReadOnlyProperty = _ReadOnlyProperty; 16 | @synthesize ReadOnlyPropertyX = _ReadOnlyPropertyX; 17 | @end 18 | -------------------------------------------------------------------------------- /examples/SemaObjC/arc-unavailable-system-function.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin11 -fobjc-arc -verify %s 2 | // rdar://10186625 3 | 4 | # 1 "" 5 | # 1 "/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h" 1 3 6 | id * foo(); // expected-note {{declaration uses type that is ill-formed in ARC}} 7 | 8 | # 1 "arc-unavailable-system-function.m" 2 9 | void ret() { 10 | foo(); // expected-error {{'foo' is unavailable in ARC}} 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/SemaObjC/arc-unsafe_unretained.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fblocks %s 2 | // RUN: %clang_cc1 -fsyntax-only -verify -fblocks -fobjc-arc %s 3 | // expected-no-diagnostics 4 | 5 | struct X { 6 | __unsafe_unretained id object; 7 | int (^ __unsafe_unretained block)(int, int); 8 | }; 9 | 10 | void f(struct X x) { 11 | x.object = 0; 12 | x.block = ^(int x, int y) { return x + y; }; 13 | } 14 | -------------------------------------------------------------------------------- /examples/SemaObjC/assign-rvalue-message.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // RUN: %clang_cc1 -std=c++98 -x objective-c++ -triple x86_64-apple-darwin10 -fsyntax-only -verify -Wno-objc-root-class %s 3 | // RUN: %clang_cc1 -std=c++11 -x objective-c++ -triple x86_64-apple-darwin10 -fsyntax-only -verify -Wno-objc-root-class %s 4 | // rdar://9005189 5 | 6 | @interface Foo 7 | @end 8 | 9 | struct Bar { 10 | int x; 11 | }; 12 | 13 | @implementation Foo { 14 | struct Bar bar; 15 | } 16 | 17 | - (const struct Bar)bar { 18 | return bar; 19 | } 20 | 21 | - (void)baz { 22 | bar.x = 0; 23 | [self bar].x = 10; // expected-error-re {{{{assigning to 'readonly' return result of an Objective-C message not allowed|expression is not assignable}}}} 24 | } 25 | @end 26 | -------------------------------------------------------------------------------- /examples/SemaObjC/at-defs.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple i386-unknown-unknown -fobjc-runtime=macosx-fragile-10.5 %s -fsyntax-only 2 | 3 | @interface Test { 4 | double a; 5 | } 6 | @end 7 | @implementation Test 8 | @end 9 | @interface TestObject : Test { 10 | @public 11 | float bar; 12 | int foo; 13 | } 14 | @end 15 | @implementation TestObject 16 | @end 17 | struct wibble { 18 | @defs(TestObject) 19 | }; 20 | 21 | 22 | int main(void) 23 | { 24 | TestObject * a = (id)malloc(100); 25 | a->foo = 12; 26 | printf("12: %d\n", ((struct wibble*)a)->foo); 27 | printf("%d: %d\n", ((char*)&(((struct wibble*)a)->foo)) - (char*)a, ((char*)&(a->foo)) - (char*)a); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /examples/SemaObjC/attr-called-once.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -fsyntax-only -fobjc-arc -fblocks %s 2 | 3 | #define CALLED_ONCE __attribute__((called_once)) 4 | 5 | void test1(int x CALLED_ONCE); // expected-error{{'called_once' attribute only applies to function-like parameters}} 6 | void test2(double x CALLED_ONCE); // expected-error{{'called_once' attribute only applies to function-like parameters}} 7 | 8 | void test3(void (*foo)() CALLED_ONCE); // no-error 9 | void test4(int (^foo)(int) CALLED_ONCE); // no-error 10 | 11 | void test5(void (*foo)() __attribute__((called_once(1)))); 12 | // expected-error@-1{{'called_once' attribute takes no arguments}} 13 | void test6(void (*foo)() __attribute__((called_once("str1", "str2")))); 14 | // expected-error@-1{{'called_once' attribute takes no arguments}} 15 | 16 | CALLED_ONCE void test7(); // expected-warning{{'called_once' attribute only applies to parameters}} 17 | void test8() { 18 | void (*foo)() CALLED_ONCE; // expected-warning{{'called_once' attribute only applies to parameters}} 19 | foo(); 20 | } 21 | -------------------------------------------------------------------------------- /examples/SemaObjC/attr-cleanup.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -verify -fsyntax-only 2 | // expected-no-diagnostics 3 | 4 | @class NSString; 5 | 6 | void c1(id *a); 7 | 8 | void t1() 9 | { 10 | NSString *s __attribute((cleanup(c1))); 11 | } 12 | -------------------------------------------------------------------------------- /examples/SemaObjC/attr-deprecated-pch.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -DBOTH -verify %s 2 | // If the decls come from a pch, the behavior shouldn't change: 3 | // RUN: %clang_cc1 -x objective-c-header %s -emit-pch -o %t 4 | // RUN: %clang_cc1 -DUSES -include-pch %t -fsyntax-only -verify %s 5 | // expected-no-diagnostics 6 | 7 | // The slightly strange ifdefs are so that the command that builds the gch file 8 | // doesn't need any -D switches, for these would get embedded in the gch. 9 | 10 | #ifndef USES 11 | @interface Interface1 12 | - (void)partiallyUnavailableMethod; 13 | @end 14 | @interface Interface2 15 | - (void)partiallyUnavailableMethod __attribute__((unavailable)); 16 | @end 17 | #endif 18 | 19 | #if defined(USES) || defined(BOTH) 20 | void f(id a) { 21 | [a partiallyUnavailableMethod]; // no warning, `a` could be an Interface1. 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /examples/SemaObjC/attr-malloc.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -fsyntax-only -fblocks %s 2 | 3 | @interface TestAttrMallocOnMethods {} 4 | - (id) test1 __attribute((malloc)); // expected-warning {{attribute only applies to functions}} 5 | - (int) test2 __attribute((malloc)); // expected-warning {{attribute only applies to functions}} 6 | @end 7 | 8 | id bar(void) __attribute((malloc)); // no-warning 9 | 10 | typedef void (^bptr)(void); 11 | bptr baz(void) __attribute((malloc)); // no-warning 12 | 13 | __attribute((malloc)) id (*f)(); // expected-warning {{attribute only applies to functions}} 14 | __attribute((malloc)) bptr (*g)(); // expected-warning {{attribute only applies to functions}} 15 | __attribute((malloc)) void *(^h)(); // expected-warning {{attribute only applies to functions}} 16 | 17 | -------------------------------------------------------------------------------- /examples/SemaObjC/attr-nodebug.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | @interface NSObject 4 | - (void)doSomething __attribute__((nodebug)); 5 | @end 6 | -------------------------------------------------------------------------------- /examples/SemaObjC/attr-ns_returns_retained.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s 2 | // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fblocks -verify %s 3 | 4 | // rdar://20130079 5 | 6 | #if __has_feature(objc_arc) 7 | __attribute__((ns_returns_retained)) id (^invalidBlockRedecl)(); // expected-note {{previous definition is here}} 8 | id (^invalidBlockRedecl)(); //expected-error {{redefinition of 'invalidBlockRedecl' with a different type: 'id (^__strong)()' vs 'id ((^__strong))() __attribute__((ns_returns_retained))'}} 9 | #else 10 | __attribute__((ns_returns_retained)) id (^invalidBlockRedecl)(); 11 | id (^invalidBlockRedecl)(); 12 | #endif 13 | 14 | typedef __attribute__((ns_returns_retained)) id (^blockType)(); 15 | 16 | typedef __attribute__((ns_returns_retained)) int (^invalidBlockType)(); // expected-warning {{'ns_returns_retained' attribute only applies to functions that return an Objective-C object}} 17 | 18 | __attribute__((ns_returns_retained)) int functionDecl(); // expected-warning {{'ns_returns_retained' attribute only applies to functions that return an Objective-C object}} 19 | -------------------------------------------------------------------------------- /examples/SemaObjC/attr-objc-exception.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -fsyntax-only -verify 2 | 3 | __attribute__((__objc_exception__)) 4 | @interface NSException { 5 | int x; 6 | } 7 | 8 | @end 9 | 10 | 11 | __attribute__((__objc_exception__)) // expected-error {{'__objc_exception__' attribute only applies to Objective-C interfaces}} 12 | int X; 13 | 14 | __attribute__((__objc_exception__)) // expected-error {{'__objc_exception__' attribute only applies to Objective-C interfaces}} 15 | void foo(); 16 | 17 | -------------------------------------------------------------------------------- /examples/SemaObjC/attr-objc-non-lazy.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -Wno-objc-root-class -fsyntax-only %s 2 | 3 | __attribute__((objc_nonlazy_class)) 4 | @interface A 5 | @end 6 | @implementation A 7 | @end 8 | 9 | __attribute__((objc_nonlazy_class)) int X; // expected-error {{'objc_nonlazy_class' attribute only applies to Objective-C interfaces}} 10 | 11 | __attribute__((objc_nonlazy_class())) 12 | @interface B 13 | @end 14 | @implementation B 15 | @end 16 | 17 | __attribute__((objc_nonlazy_class("foo"))) // expected-error{{'objc_nonlazy_class' attribute takes no arguments}} 18 | @interface C 19 | @end 20 | @implementation C 21 | @end 22 | 23 | __attribute__((objc_nonlazy_class)) // expected-error {{'objc_nonlazy_class' attribute only applies to Objective-C interfaces}} 24 | @protocol B 25 | @end 26 | 27 | __attribute__((objc_nonlazy_class)) // expected-error {{'objc_nonlazy_class' attribute only applies to Objective-C interfaces}} 28 | void foo(); 29 | 30 | @interface E 31 | @end 32 | 33 | __attribute__((objc_nonlazy_class)) 34 | @implementation E 35 | @end 36 | 37 | __attribute__((objc_nonlazy_class)) 38 | @implementation E (MyCat) 39 | @end 40 | -------------------------------------------------------------------------------- /examples/SemaObjC/attr-objc-runtime-visible.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -fsyntax-only %s 2 | 3 | __attribute__((objc_runtime_visible)) 4 | @interface A 5 | @end 6 | 7 | @interface A(X) 8 | @end 9 | 10 | @implementation A(X) // expected-error{{cannot implement a category for class 'A' that is only visible via the Objective-C runtime}} 11 | @end 12 | 13 | @interface B : A 14 | @end 15 | 16 | @implementation B // expected-error{{cannot implement subclass 'B' of a superclass 'A' that is only visible via the Objective-C runtime}} 17 | @end 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/SemaObjC/attr-print.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -fobjc-arc -ast-print | FileCheck %s 2 | 3 | __strong id x; 4 | id y; 5 | __strong id z; 6 | 7 | // CHECK: __strong id x; 8 | // CHECK-NOT: __strong id y; 9 | // CHECK: __strong id z; 10 | -------------------------------------------------------------------------------- /examples/SemaObjC/attr-root-class.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wattributes -Wobjc-root-class %s 2 | @interface RootClass {} // expected-warning {{class 'RootClass' defined without specifying a base class}} \ 3 | // expected-note {{add a super class to fix this problem}} 4 | @end 5 | @implementation RootClass 6 | @end 7 | 8 | __attribute__((objc_root_class)) 9 | @interface NonRootClass : RootClass // expected-error {{objc_root_class attribute may only be specified on a root class declaration}} 10 | @end 11 | @implementation NonRootClass 12 | @end 13 | 14 | __attribute__((objc_root_class)) static void nonClassDeclaration() // expected-error {{'objc_root_class' attribute only applies to Objective-C interfaces}} 15 | { 16 | } 17 | 18 | __attribute__((objc_root_class(1))) // expected-error {{'objc_root_class' attribute takes no arguments}} 19 | @interface I1 20 | @end 21 | -------------------------------------------------------------------------------- /examples/SemaObjC/attr-swift_bridged_typedef.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -fsyntax-only %s 2 | 3 | @interface NSString 4 | @end 5 | 6 | typedef NSString *NSStringAlias __attribute__((__swift_bridged_typedef__)); 7 | 8 | typedef int IntAlias __attribute__((__swift_bridged_typedef__)); 9 | 10 | struct __attribute__((swift_bridged_typedef)) S {}; 11 | // expected-error@-1 {{'swift_bridged_typedef' attribute only applies to typedefs}} 12 | 13 | typedef unsigned char UnsignedChar __attribute__((__swift_bridged_typedef__("UnsignedChar"))); 14 | // expected-error@-1 {{'__swift_bridged_typedef__' attribute takes no arguments}} 15 | -------------------------------------------------------------------------------- /examples/SemaObjC/attr-swift_newtype.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | typedef int Bad1 __attribute__((swift_newtype(invalid))); 4 | // expected-warning@-1 {{'swift_newtype' attribute argument not supported: 'invalid'}} 5 | typedef int Bad2 __attribute__((swift_newtype())); 6 | // expected-error@-1 {{argument required after attribute}} 7 | typedef int Bad3 __attribute__((swift_newtype(invalid, ignored))); 8 | // expected-error@-1 {{expected ')'}} 9 | // expected-note@-2 {{to match this '('}} 10 | // expected-warning@-3 {{'swift_newtype' attribute argument not supported: 'invalid'}} 11 | 12 | struct __attribute__((__swift_newtype__(struct))) Bad4 {}; 13 | // expected-error@-1 {{'__swift_newtype__' attribute only applies to typedefs}} 14 | -------------------------------------------------------------------------------- /examples/SemaObjC/attr-swift_objc_members.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -fsyntax-only %s 2 | 3 | #if !__has_attribute(swift_objc_members) 4 | #error cannot verify presence of swift_objc_members attribute 5 | #endif 6 | 7 | __attribute__((__swift_objc_members__)) 8 | __attribute__((__objc_root_class__)) 9 | @interface I 10 | @end 11 | 12 | __attribute__((swift_objc_members)) 13 | @protocol P 14 | @end 15 | // expected-error@-3 {{'swift_objc_members' attribute only applies to Objective-C interfaces}} 16 | 17 | __attribute__((swift_objc_members)) 18 | extern void f(void); 19 | // expected-error@-2 {{'swift_objc_members' attribute only applies to Objective-C interfaces}} 20 | 21 | // expected-error@+1 {{'__swift_objc_members__' attribute takes no arguments}} 22 | __attribute__((__swift_objc_members__("J"))) 23 | @interface J 24 | @end 25 | -------------------------------------------------------------------------------- /examples/SemaObjC/attr-swift_private.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -fsyntax-only -fobjc-arc %s 2 | 3 | __attribute__((__swift_private__)) 4 | @protocol P 5 | @end 6 | 7 | __attribute__((__swift_private__)) 8 | @interface I 9 | @end 10 | 11 | @interface J 12 | @property id property __attribute__((__swift_private__)); 13 | - (void)instanceMethod __attribute__((__swift_private__)); 14 | + (void)classMethod __attribute__((__swift_private__)); 15 | @end 16 | 17 | void f(void) __attribute__((__swift_private__)); 18 | 19 | struct __attribute__((__swift_private__)) S {}; 20 | 21 | enum __attribute__((__swift_private__)) E { 22 | one, 23 | two, 24 | }; 25 | 26 | typedef struct { } T __attribute__((__swift_private__)); 27 | 28 | void g(void) __attribute__((__swift_private__("private"))); 29 | // expected-error@-1 {{'__swift_private__' attribute takes no arguments}} 30 | -------------------------------------------------------------------------------- /examples/SemaObjC/autoreleasepool.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | void *objc_autoreleasepool_push(); 4 | void autoreleasepool_pop(void*); 5 | 6 | @interface AUTORP @end 7 | 8 | @implementation AUTORP 9 | - (void) unregisterTask:(id) task { 10 | goto L; // expected-error {{cannot jump}} 11 | 12 | @autoreleasepool { // expected-note {{jump bypasses auto release push of @autoreleasepool block}} 13 | void *tmp = objc_autoreleasepool_push(); 14 | L: 15 | autoreleasepool_pop(tmp); 16 | @autoreleasepool { 17 | return; 18 | } 19 | } 20 | } 21 | @end 22 | 23 | -------------------------------------------------------------------------------- /examples/SemaObjC/avoid-unavailable-implementation-warning-in-app-extension.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple arm64-apple-ios11 -fapplication-extension -Wdeprecated-implementations -verify -Wno-objc-root-class %s 2 | // RUN: %clang_cc1 -triple arm64-apple-tvos11 -fapplication-extension -Wdeprecated-implementations -verify -Wno-objc-root-class %s 3 | // Declarations marked as 'unavailable' in an app extension should not generate a 4 | // warning on implementation. 5 | 6 | @interface Parent 7 | - (void)ok __attribute__((availability(ios_app_extension,unavailable,message="not available"))); 8 | - (void)reallyUnavail __attribute__((availability(ios,unavailable))); // expected-note {{method 'reallyUnavail' declared here}} 9 | - (void)reallyUnavail2 __attribute__((unavailable)); // expected-note {{method 'reallyUnavail2' declared here}} 10 | @end 11 | 12 | @interface Child : Parent 13 | @end 14 | 15 | @implementation Child 16 | 17 | - (void)ok { // no warning. 18 | } 19 | - (void)reallyUnavail { // expected-warning {{implementing unavailable method}} 20 | } 21 | - (void)reallyUnavail2 { // expected-warning {{implementing unavailable method}} 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /examples/SemaObjC/bad-property-synthesis-crash.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // rdar://10177744 3 | 4 | @interface Foo 5 | @property (nonatomic, retain) NSString* what; // expected-error {{unknown type name 'NSString'}} \ 6 | // expected-error {{property with}} \ 7 | // expected-note {{previous definition is here}} 8 | @end 9 | 10 | @implementation Foo 11 | - (void) setWhat: (NSString*) value { // expected-error {{expected a type}} \ 12 | // expected-warning {{conflicting parameter types in implementation of}} 13 | __what; // expected-error {{use of undeclared identifier}} \ 14 | // expected-warning {{expression result unused}} 15 | } 16 | @synthesize what; // expected-note {{'what' declared here}} 17 | @end 18 | 19 | @implementation Bar // expected-warning {{cannot find interface declaration for}} 20 | - (NSString*) what { // expected-error {{expected a type}} 21 | return __what; // expected-error {{use of undeclared identifier}} 22 | } 23 | @end 24 | -------------------------------------------------------------------------------- /examples/SemaObjC/bad-receiver-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @interface I 4 | - (id) retain; 5 | @end 6 | 7 | int objc_lookUpClass(const char*); 8 | 9 | void __raiseExc1() { 10 | [objc_lookUpClass("NSString") retain]; // expected-warning {{receiver type 'int' is not 'id'}} 11 | } 12 | 13 | typedef const struct __CFString * CFStringRef; 14 | 15 | void func() { 16 | CFStringRef obj; 17 | 18 | [obj self]; // expected-warning {{receiver type 'CFStringRef' (aka 'const struct __CFString *') is not 'id'}} \\ 19 | expected-warning {{method '-self' not found}} 20 | } 21 | -------------------------------------------------------------------------------- /examples/SemaObjC/block-as-object.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks 2 | // expected-no-diagnostics 3 | 4 | @interface Whatever 5 | - copy; 6 | @end 7 | 8 | typedef long (^MyBlock)(id obj1, id obj2); 9 | 10 | void foo(MyBlock b) { 11 | id bar = [b copy]; 12 | } 13 | 14 | void foo2(id b) { 15 | } 16 | 17 | void foo3(void (^block)(void)) { 18 | foo2(block); 19 | id x; 20 | foo(x); 21 | } 22 | -------------------------------------------------------------------------------- /examples/SemaObjC/block-attr.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fblocks -fobjc-gc-only %s 2 | // RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -fsyntax-only -verify -fblocks -fobjc-gc-only %s 3 | 4 | @interface Thing {} 5 | 6 | @property void(^someBlock)(void); // expected-warning {{'copy' attribute must be specified for the block property}} 7 | @property(copy) void(^OK)(void); 8 | 9 | // rdar://8820813 10 | @property (readonly) void (^block)(void); // readonly property is OK 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /examples/SemaObjC/block-id-as-block-argtype.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks 2 | // rdar://10734265 3 | 4 | @class NSObject; 5 | typedef void (^block1_t)(int arg); 6 | typedef void (^block2_t)(block1_t arg); 7 | typedef void (^block3_t)(NSObject *arg); 8 | typedef void (^block4_t)(id arg); 9 | 10 | void fn(block4_t arg); // expected-note {{passing argument to parameter 'arg' here}} 11 | 12 | void another_fn(block2_t arg); 13 | 14 | int main() { 15 | block1_t b1; 16 | block2_t b2; 17 | block3_t b3; 18 | block3_t b4; 19 | block4_t b5; 20 | 21 | fn(b1); // expected-error {{incompatible block pointer types passing 'block1_t' (aka 'void (^)(int)') to parameter of type 'block4_t' (aka 'void (^)(id)')}} 22 | fn(b2); // must succeed: block1_t *is* compatible with id 23 | fn(b3); // succeeds: NSObject* compatible with id 24 | fn(b4); // succeeds: id compatible with id 25 | 26 | another_fn(b5); 27 | } 28 | -------------------------------------------------------------------------------- /examples/SemaObjC/block-ivar.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks 2 | // expected-no-diagnostics 3 | 4 | @interface NSObject { 5 | struct objc_object *isa; 6 | } 7 | @end 8 | @interface Foo : NSObject { 9 | int _prop; 10 | } 11 | @end 12 | 13 | @implementation Foo 14 | - (int)doSomething { 15 | int (^blk)(void) = ^{ return _prop; }; 16 | return blk(); 17 | } 18 | 19 | @end 20 | 21 | -------------------------------------------------------------------------------- /examples/SemaObjC/block-literal-with-attribute.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks -fobjc-arc 2 | // RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks 3 | 4 | __auto_type block = ^ id __attribute__((ns_returns_retained)) (id filter) { 5 | return filter; // ok 6 | }; 7 | __auto_type block2 = ^ __attribute__((ns_returns_retained)) id (id filter) { 8 | return filter; // ok 9 | }; 10 | __auto_type block3 = ^ id (id filter) __attribute__((ns_returns_retained)) { 11 | return filter; // ok 12 | }; 13 | 14 | // expected-no-diagnostics 15 | -------------------------------------------------------------------------------- /examples/SemaObjC/block-on-method-param.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fblocks -Wno-objc-root-class %s 2 | // RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -fsyntax-only -verify -fblocks -Wno-objc-root-class %s 3 | 4 | // rdar://10681443 5 | @interface I 6 | - (void) compileSandboxProfileAndReturnError:(__attribute__((__blocks__(byref))) id)errorp; // expected-error {{__block attribute not allowed, only allowed on local variables}} 7 | @end 8 | 9 | @implementation I 10 | - (void) compileSandboxProfileAndReturnError:(__attribute__((__blocks__(byref))) id)errorp {} // expected-error {{__block attribute not allowed, only allowed on local variables}} 11 | @end 12 | 13 | -------------------------------------------------------------------------------- /examples/SemaObjC/block-return.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fblocks -fobjc-gc-only %s 2 | // expected-no-diagnostics 3 | // rdar://8979379 4 | 5 | @interface NSString 6 | - (__attribute__((objc_gc(strong))) const char *)UTF8String; 7 | @end 8 | 9 | int main() { 10 | __attribute__((objc_gc(strong))) char const *(^libraryNameForIndex)() = ^() { 11 | NSString *moduleName; 12 | return [moduleName UTF8String]; 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /examples/SemaObjC/builtin_objc_assign_ivar.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -x objective-c %s -fsyntax-only -verify 2 | // expected-no-diagnostics 3 | // rdar://9362887 4 | 5 | typedef __typeof__(((int*)0)-((int*)0)) ptrdiff_t; 6 | extern id objc_assign_ivar(id value, id dest, ptrdiff_t offset); 7 | 8 | -------------------------------------------------------------------------------- /examples/SemaObjC/builtin_objc_msgSend.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -fsyntax-only -verify 2 | // expected-no-diagnostics 3 | // rdar://8632525 4 | extern id objc_msgSend(id self, SEL op, ...); 5 | 6 | // rdar://12489098 7 | struct objc_super { 8 | id receiver; 9 | Class super_class; 10 | }; 11 | 12 | extern __attribute__((visibility("default"))) id objc_msgSendSuper(struct objc_super *super, SEL op, ...) 13 | __attribute__((availability(macosx,introduced=10.0))); 14 | 15 | extern __attribute__((visibility("default"))) void objc_msgSendSuper_stret(struct objc_super *super, SEL op, ...) 16 | __attribute__((availability(macosx,introduced=10.0))); 17 | 18 | extern __attribute__((visibility("default"))) void objc_msgSend_stret(id self, SEL op, ...) 19 | __attribute__((availability(macosx,introduced=10.0))); 20 | 21 | -------------------------------------------------------------------------------- /examples/SemaObjC/builtin_objc_nslog.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -x objective-c %s -fsyntax-only -verify 2 | 3 | #include 4 | 5 | void f1(id arg) { 6 | NSLog(@"%@", arg); // expected-warning {{implicitly declaring library function 'NSLog' with type 'void (id, ...)'}} \ 7 | // expected-note {{include the header or explicitly provide a declaration for 'NSLog'}} 8 | } 9 | 10 | void f2(id str, va_list args) { 11 | NSLogv(@"%@", args); // expected-warning {{implicitly declaring library function 'NSLogv' with type }} \ 12 | // expected-note {{include the header or explicitly provide a declaration for 'NSLogv'}} 13 | } 14 | -------------------------------------------------------------------------------- /examples/SemaObjC/catch-invalid.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple thumbv7-unknown-windows-msvc -fobjc-exceptions -fobjc-runtime=ios -verify %s 2 | 3 | extern void g(void); 4 | void f() { 5 | @try { 6 | g(); 7 | } @catch (Class c) { // expected-error{{@catch parameter is not a pointer to an interface type}} 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/SemaObjC/catch-stmt.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -fobjc-exceptions %s 2 | @interface A @end 3 | @protocol P; 4 | 5 | void f() { 6 | @try { 7 | } @catch (void a) { // expected-error{{@catch parameter is not a pointer to an interface type}} 8 | } @catch (int) { // expected-error{{@catch parameter is not a pointer to an interface type}} 9 | } @catch (int *b) { // expected-error{{@catch parameter is not a pointer to an interface type}} 10 | } @catch (id

c) { // expected-error{{illegal qualifiers on @catch parameter}} 11 | } @catch(A* a) { } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /examples/SemaObjC/category-method-lookup-2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | typedef struct objc_class *Class; 5 | @interface NSObject 6 | - (Class)class; 7 | @end 8 | @interface Bar : NSObject 9 | @end 10 | @interface Bar (Cat) 11 | @end 12 | 13 | // NOTE: No class implementation for Bar precedes this category definition. 14 | @implementation Bar (Cat) 15 | 16 | // private method. 17 | + classMethod { return self; } 18 | 19 | - instanceMethod { 20 | [[self class] classMethod]; 21 | return 0; 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /examples/SemaObjC/category-method-lookup.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | 4 | @interface Foo 5 | @end 6 | @implementation Foo 7 | @end 8 | 9 | @implementation Foo(Whatever) 10 | +(float)returnsFloat { return 7.0; } 11 | @end 12 | 13 | @interface Foo (MoreStuff) 14 | +(int)returnsInt; 15 | @end 16 | 17 | @implementation Foo (MoreStuff) 18 | +(int)returnsInt { 19 | return 0; 20 | } 21 | 22 | +(void)returnsNothing { 23 | } 24 | -(int)callsReturnsInt { 25 | float f = [Foo returnsFloat]; // GCC doesn't find this method (which is a bug IMHO). 26 | [Foo returnsNothing]; 27 | return [Foo returnsInt]; 28 | } 29 | @end 30 | 31 | int main() {return 0;} 32 | 33 | -------------------------------------------------------------------------------- /examples/SemaObjC/class-bitfield.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -fobjc-runtime=macosx-fragile-10.5 -fsyntax-only -verify 2 | 3 | @interface X 4 | { 5 | int a : -1; // expected-error{{bit-field 'a' has negative width}} 6 | 7 | // rdar://6081627 8 | int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds width of its type (32 bits)}} 9 | 10 | int c : (1 + 0.25); // expected-error{{integer constant expression must have integer type}} 11 | int d : (int)(1 + 0.25); 12 | 13 | // rdar://6138816 14 | int e : 0; // expected-error {{bit-field 'e' has zero width}} 15 | } 16 | @end 17 | 18 | @interface Base { 19 | int i; 20 | } 21 | @end 22 | 23 | @interface WithBitFields: Base { 24 | void *isa; // expected-note {{previous definition is here}} 25 | unsigned a: 5; 26 | signed b: 4; 27 | int c: 5; // expected-note {{previous definition is here}} 28 | } 29 | @end 30 | 31 | @implementation WithBitFields { 32 | char *isa; // expected-error {{instance variable 'isa' has conflicting type: 'char *' vs 'void *'}} 33 | unsigned a: 5; 34 | signed b: 4; 35 | int c: 3; // expected-error {{instance variable 'c' has conflicting bit-field width}} 36 | } 37 | @end 38 | -------------------------------------------------------------------------------- /examples/SemaObjC/class-conforming-protocol-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -Wduplicate-method-match -fsyntax-only -verify %s 2 | 3 | @protocol P1 @end 4 | @protocol P2 @end 5 | @protocol P3 @end 6 | 7 | @interface INTF 8 | - (INTF*) METH1; // expected-note {{previous declaration is here}} 9 | - (INTF*) METH1; // expected-error {{duplicate declaration of method 'METH1'}} 10 | 11 | - (INTF*) METH2; // expected-note {{previous declaration is here}} 12 | - (INTF*) METH2; // expected-error {{duplicate declaration of method 'METH2'}} 13 | 14 | - (INTF*) METH3; // expected-note {{previous declaration is here}} 15 | - (INTF*) METH3; // expected-warning {{multiple declarations of method 'METH3' found and ignored}} 16 | 17 | @end 18 | 19 | INTF* p1; 20 | 21 | -------------------------------------------------------------------------------- /examples/SemaObjC/class-conforming-protocol-2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -Wmethod-signatures -fsyntax-only -verify %s 2 | 3 | @protocol NSWindowDelegate @end 4 | 5 | @protocol IBStringsTableWindowDelegate 6 | @end 7 | 8 | @interface NSWindow 9 | - (void)setDelegate:(id )anObject; // expected-note {{previous definition is here}} 10 | - (id ) delegate; // expected-note {{previous definition is here}} 11 | @end 12 | 13 | 14 | @interface IBStringsTableWindow : NSWindow {} 15 | @end 16 | 17 | @implementation IBStringsTableWindow 18 | - (void)setDelegate:(id )delegate { // expected-warning {{conflicting parameter types in implementation of 'setDelegate:'}} 19 | } 20 | - (id )delegate { // expected-warning {{conflicting return type in implementation of 'delegate':}} 21 | return 0; 22 | } 23 | @end 24 | -------------------------------------------------------------------------------- /examples/SemaObjC/class-extension-after-implementation.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // rdar://7822210 3 | 4 | @interface A @end 5 | 6 | @implementation A @end // expected-note {{class implementation is declared here}} 7 | 8 | @interface A () // expected-error {{cannot declare class extension for 'A' after class implementation}} 9 | -(void) im0; 10 | @end 11 | 12 | -------------------------------------------------------------------------------- /examples/SemaObjC/class-getter-using-dotsyntax.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | 4 | typedef struct objc_class *Class; 5 | 6 | struct objc_class { 7 | Class isa; 8 | }; 9 | 10 | typedef struct objc_object { 11 | Class isa; 12 | } *id; 13 | 14 | @interface XCActivityLogSection 15 | + (unsigned)serializationFormatVersion; 16 | + (unsigned)sectionByDeserializingData; 17 | + (Class)retursClass; 18 | @end 19 | 20 | @implementation XCActivityLogSection 21 | 22 | + (unsigned)serializationFormatVersion 23 | { 24 | 25 | return 0; 26 | } 27 | + (unsigned)sectionByDeserializingData { 28 | unsigned version; 29 | return self.serializationFormatVersion; 30 | } 31 | 32 | + (Class)retursClass { 33 | Class version; 34 | // FIXIT. (*version).isa does not work. Results in compiler error. 35 | return version->isa; 36 | } 37 | 38 | @end 39 | 40 | 41 | -------------------------------------------------------------------------------- /examples/SemaObjC/class-method-self.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -Wno-objc-root-class %s 2 | 3 | @interface XX 4 | 5 | - (void)addObserver:(XX*)o; // expected-note 2{{passing argument to parameter 'o' here}} 6 | 7 | @end 8 | 9 | @interface YY 10 | 11 | + (void)classMethod; 12 | 13 | @end 14 | 15 | @implementation YY 16 | 17 | static XX *obj; 18 | 19 | + (void)classMethod { 20 | [obj addObserver:self]; // expected-warning {{incompatible pointer types sending 'Class' to parameter of type 'XX *'}} 21 | Class whatever; 22 | [obj addObserver:whatever]; // expected-warning {{incompatible pointer types sending 'Class' to parameter of type 'XX *'}} 23 | } 24 | @end 25 | -------------------------------------------------------------------------------- /examples/SemaObjC/class-protocol.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | // pr5552 4 | 5 | @interface Protocol 6 | @end 7 | 8 | -------------------------------------------------------------------------------- /examples/SemaObjC/class-stub-attr-unsupported.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang -target i386-apple-darwin -fsyntax-only -Xclang -verify %s 2 | // RUN: %clang -target i386-apple-darwin -x objective-c++ -fsyntax-only -Xclang -verify %s 3 | 4 | @interface NSObject 5 | @end 6 | 7 | __attribute__((objc_class_stub)) // expected-warning {{'objc_class_stub' attribute ignored}} 8 | __attribute__((objc_subclassing_restricted)) 9 | @interface StubClass : NSObject 10 | @end 11 | -------------------------------------------------------------------------------- /examples/SemaObjC/compound-init.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | @interface A 3 | @end 4 | 5 | void f() { 6 | (A){ 0 }; // expected-error{{cannot initialize Objective-C class type 'A'}} 7 | } 8 | -------------------------------------------------------------------------------- /examples/SemaObjC/comptypes-2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | #define nil (void *)0; 5 | #define Nil (void *)0; 6 | 7 | @protocol MyProtocol 8 | - (void) foo; 9 | @end 10 | 11 | @interface MyClass 12 | @end 13 | 14 | int main() 15 | { 16 | id obj = nil; 17 | id obj_p = nil; 18 | MyClass *obj_c = nil; 19 | Class obj_C = Nil; 20 | 21 | /* All these casts should generate no warnings. */ 22 | 23 | obj = (id)obj_p; 24 | obj = (id)obj_c; 25 | obj = (id)obj_C; 26 | obj_c = (MyClass *)obj; 27 | obj_c = (MyClass *)obj_p; 28 | obj_c = (MyClass *)obj_C; 29 | obj_p = (id)obj; 30 | obj_p = (id)obj_c; 31 | obj_p = (id)obj_C; 32 | obj_C = (Class)obj; 33 | obj_C = (Class)obj_p; 34 | obj_C = (Class)obj_c; 35 | 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /examples/SemaObjC/comptypes-4.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | extern void foo(); 4 | 5 | @protocol MyProtocol @end 6 | 7 | @interface MyClass @end 8 | 9 | int main() 10 | { 11 | MyClass *obj_p; 12 | MyClass *obj_cp; 13 | 14 | obj_cp = obj_p; 15 | obj_p = obj_cp; // expected-warning {{incompatible pointer types assigning to 'MyClass *' from 'MyClass *'}} 16 | 17 | if (obj_cp == obj_p) 18 | foo(); 19 | 20 | if (obj_p == obj_cp) 21 | foo(); 22 | 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /examples/SemaObjC/comptypes-6.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s 2 | 3 | @interface Derived 4 | @end 5 | 6 | @interface Object @end 7 | 8 | extern Object* foo(void); 9 | 10 | static Derived *test(void) 11 | { 12 | Derived *m = foo(); // expected-warning {{incompatible pointer types initializing 'Derived *' with an expression of type 'Object *'}} 13 | 14 | return m; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /examples/SemaObjC/comptypes-8.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | @protocol MyProtocol 5 | @end 6 | 7 | id obj_p = 0; 8 | 9 | int main() 10 | { 11 | obj_p = 0; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /examples/SemaObjC/conditional-expr-2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @interface A 4 | @end 5 | @interface B 6 | @end 7 | 8 | void f0(int cond, A *a, B *b) { 9 | // Ensure that we can still send a message to result of incompatible 10 | // conditional expression. 11 | [ (cond ? a : b) test ]; // expected-warning{{incompatible operand types ('A *' and 'B *')}} expected-warning {{method '-test' not found}} 12 | } 13 | 14 | @interface NSKey @end 15 | @interface KeySub : NSKey @end 16 | 17 | @interface UpdatesList @end 18 | 19 | void foo (int i, NSKey *NSKeyValueCoding_NullValue, UpdatesList *nukedUpdatesList) 20 | { 21 | id obj; 22 | NSKey *key; 23 | KeySub *keysub; 24 | 25 | obj = i ? NSKeyValueCoding_NullValue : nukedUpdatesList; // expected-warning{{incompatible operand types ('NSKey *' and 'UpdatesList *')}} 26 | key = i ? NSKeyValueCoding_NullValue : nukedUpdatesList; // expected-warning{{incompatible operand types ('NSKey *' and 'UpdatesList *')}} 27 | key = i ? NSKeyValueCoding_NullValue : keysub; 28 | keysub = i ? NSKeyValueCoding_NullValue : keysub; // expected-warning{{incompatible pointer types assigning to 'KeySub *' from 'NSKey *'}} 29 | } 30 | -------------------------------------------------------------------------------- /examples/SemaObjC/conditional-expr-5.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | 4 | @interface PBXBuildSettingsDictionary 5 | { 6 | int i; 7 | } 8 | @end 9 | 10 | @interface XCConditionalBuildSettingsDictionary : PBXBuildSettingsDictionary 11 | { 12 | } 13 | @end 14 | 15 | @implementation PBXBuildSettingsDictionary 16 | 17 | - (XCConditionalBuildSettingsDictionary *)conditionalDictionaryForConditionSet 18 | { 19 | return i ? self : (id)0; 20 | } 21 | 22 | - (XCConditionalBuildSettingsDictionary *)conditionalDictionaryForConditionSet2 23 | { 24 | return i ? (id)0 : self; 25 | } 26 | @end 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/SemaObjC/conditional-expr-7.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | // radar 7682116 4 | 5 | @interface Super @end 6 | 7 | @interface NSArray : Super @end 8 | @interface NSSet : Super @end 9 | 10 | @protocol MyProtocol 11 | - (void)myMethod; 12 | @end 13 | 14 | @protocol MyProtocol2 15 | - (void)myMethod2; 16 | @end 17 | 18 | @interface NSArray() 19 | @end 20 | 21 | @interface NSSet() 22 | @end 23 | 24 | int main (int argc, const char * argv[]) { 25 | NSArray *array = (void*)0; 26 | NSSet *set = (void*)0; 27 | id instance = (argc) ? array : set; 28 | instance = (void*)0; 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /examples/SemaObjC/conflict-atomic-property.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // rdar://10260017 3 | 4 | @interface Foo 5 | @property (nonatomic, assign, atomic) float dummy; // expected-error {{property attributes 'atomic' and 'nonatomic' are mutually exclusive}} 6 | @property (nonatomic, assign) float d1; 7 | @property (atomic, assign) float d2; 8 | @property (assign) float d3; 9 | @property (atomic, nonatomic, assign) float d4; // expected-error {{property attributes 'atomic' and 'nonatomic' are mutually exclusive}} 10 | @end 11 | -------------------------------------------------------------------------------- /examples/SemaObjC/conflict-nonfragile-abi2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -fsyntax-only -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | // rdar://8225011 4 | 5 | int glob; 6 | 7 | @interface I 8 | @property int glob; 9 | @property int p; 10 | @property int le; 11 | @property int l; 12 | @property int ls; 13 | @property int r; 14 | @end 15 | 16 | // rdar://9027673 17 | // Warning on future name lookup rule is removed. 18 | @implementation I 19 | - (int) Meth { return glob; } // no warning 20 | @synthesize glob; 21 | // rdar://8248681 22 | - (int) Meth1: (int) p { 23 | extern int le; 24 | int l = 1; 25 | static int ls; 26 | register int r; 27 | p = le + ls + r; 28 | return l; 29 | } 30 | @dynamic p; 31 | @dynamic le; 32 | @dynamic l; 33 | @dynamic ls; 34 | @dynamic r; 35 | @end 36 | 37 | 38 | -------------------------------------------------------------------------------- /examples/SemaObjC/conversion.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -Wconversion -fsyntax-only %s -verify 2 | 3 | typedef signed char BOOL; 4 | __attribute__((objc_root_class)) @interface RDar14415662 5 | @property (readonly) BOOL stuff; 6 | @property (readwrite) BOOL otherStuff; 7 | @end 8 | 9 | void radar14415662(RDar14415662 *f, char x, int y) { 10 | f.otherStuff = !f.stuff; // no-warning 11 | BOOL b = !f.stuff; // no-warning 12 | 13 | // True positive to sanity check warning is working. 14 | x = y; // expected-warning {{implicit conversion loses integer precision: 'int' to 'char'}} 15 | } 16 | 17 | __attribute__((objc_root_class)) @interface DoubleProp 18 | @property double d; 19 | @end 20 | 21 | void use_double_prop(DoubleProp *dp) { 22 | double local = 42; 23 | dp.d += local; // no warning 24 | } 25 | -------------------------------------------------------------------------------- /examples/SemaObjC/crash-label.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | - (NSDictionary*) _executeScript:(NSString *)source { // expected-error 2 {{expected a type}} \ 4 | // expected-error {{missing context for method declaration}} 5 | Exit: [nilArgs release]; 6 | } 7 | - (NSDictionary *) _setupKernelStandardMode:(NSString *)source { // expected-error 2 {{expected a type}} \ 8 | // expected-error {{missing context for method declaration}} 9 | Exit: if(_ciKernel && !success ) { 10 | -------------------------------------------------------------------------------- /examples/SemaObjC/crash-on-objc-bool-literal.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify %s 3 | // rdar://12456743 4 | 5 | typedef signed char BOOL; 6 | 7 | EXPORT BOOL FUNC(BOOL enabled); // expected-error {{unknown type name 'EXPORT'}} // expected-error {{expected ';' after top level declarator}} 8 | 9 | static inline BOOL MFIsPrivateVersion(void) { 10 | return __objc_yes; 11 | } 12 | -------------------------------------------------------------------------------- /examples/SemaObjC/custom-atomic-property.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -Wcustom-atomic-properties -verify -Wno-objc-root-class %s 2 | 3 | @interface Foo 4 | @property (assign) Foo *myProp; // expected-note {{property declared here}} expected-note {{property declared here}} 5 | @end 6 | 7 | @implementation Foo 8 | -(Foo*)myProp {return 0;} // expected-warning {{atomic by default property 'myProp' has a user defined getter (property should be marked 'atomic' if this is intended)}} 9 | -(void)setMyProp:(Foo*)e {} // expected-warning {{atomic by default property 'myProp' has a user defined setter (property should be marked 'atomic' if this is intended)}} 10 | @end 11 | 12 | @interface Foo2 { 13 | Foo *myProp; 14 | } 15 | @property (assign) Foo *myProp; 16 | @end 17 | 18 | @implementation Foo2 19 | @synthesize myProp; // no warnings. 20 | @end 21 | -------------------------------------------------------------------------------- /examples/SemaObjC/debugger-cast-result-to-id.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -funknown-anytype -fsyntax-only -fdebugger-support -fdebugger-cast-result-to-id -verify %s 2 | 3 | extern __unknown_anytype test0; 4 | extern __unknown_anytype test1(); 5 | 6 | void test_unknown_anytype_receiver() { 7 | (void)(int)[[test0 unknownMethod] otherUnknownMethod];; 8 | (void)(id)[[test1() unknownMethod] otherUnknownMethod]; 9 | id x = test0; 10 | id y = test1(); 11 | } 12 | 13 | // rdar://10988847 14 | @class NSString; // expected-note {{forward declaration of class here}} 15 | 16 | void rdar10988847() { 17 | id s = [NSString stringWithUTF8String:"foo"]; // expected-warning {{receiver 'NSString' is a forward class and corresponding @interface may not exist}} 18 | } 19 | -------------------------------------------------------------------------------- /examples/SemaObjC/debugger-support.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fdebugger-support %s -emit-llvm -o - | FileCheck %s 2 | 3 | // rdar://problem/9416370 4 | void test0(id x) { 5 | struct A { int w, x, y, z; }; 6 | struct A result = (struct A) [x makeStruct]; 7 | // CHECK: define{{.*}} void @test0( 8 | // CHECK: [[X:%.*]] = alloca i8*, align 8 9 | // CHECK-NEXT: [[RESULT:%.*]] = alloca [[A:%.*]], align 4 10 | // CHECK-NEXT: store i8* {{%.*}}, i8** [[X]], 11 | // CHECK-NEXT: [[T0:%.*]] = load i8*, i8** [[X]], 12 | // CHECK-NEXT: [[T1:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES_ 13 | // CHECK-NEXT: [[T2:%.*]] = call { i64, i64 } bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to { i64, i64 } (i8*, i8*)*)(i8* [[T0]], i8* [[T1]]) 14 | } 15 | -------------------------------------------------------------------------------- /examples/SemaObjC/default-synthesize-sourceloc.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -ast-dump %s | FileCheck %s 2 | 3 | // Test that accessor stubs for default-synthesized ObjC accessors 4 | // have a valid source location. 5 | 6 | __attribute__((objc_root_class)) 7 | @interface NSObject 8 | + (id)alloc; 9 | @end 10 | 11 | @interface NSString : NSObject 12 | @end 13 | 14 | @interface MyData : NSObject 15 | struct Data { 16 | NSString *name; 17 | }; 18 | @property struct Data data; 19 | @end 20 | // CHECK: ObjCImplementationDecl {{.*}}line:[[@LINE+2]]{{.*}} MyData 21 | // CHECK: ObjCMethodDecl {{.*}}col:23 implicit - setData: 'void' 22 | @implementation MyData 23 | @end 24 | -------------------------------------------------------------------------------- /examples/SemaObjC/delay-parsing-cfunctions.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -Werror -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | // rdar://10387088 4 | 5 | @interface MyClass 6 | - (void)someMethod; 7 | @end 8 | 9 | @implementation MyClass 10 | - (void)someMethod { 11 | [self privateMethod]; // clang already does not warn here 12 | } 13 | 14 | int bar(MyClass * myObject) { 15 | [myObject privateMethod]; 16 | return gorfbar(myObject); 17 | } 18 | - (void)privateMethod { } 19 | 20 | int gorfbar(MyClass * myObject) { 21 | [myObject privateMethod]; 22 | [myObject privateMethod1]; 23 | return getMe + bar(myObject); 24 | } 25 | 26 | int KR(myObject) 27 | MyClass * myObject; 28 | { 29 | [myObject privateMethod]; 30 | [myObject privateMethod1]; 31 | return getMe + bar(myObject); 32 | } 33 | 34 | - (void)privateMethod1 { 35 | getMe = getMe+1; 36 | } 37 | 38 | static int getMe; 39 | 40 | static int test() { 41 | return 0; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /examples/SemaObjC/deref-interface.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -fsyntax-only -Wno-objc-root-class %s 2 | 3 | @interface NSView 4 | - (id)initWithView:(id)realView; 5 | @end 6 | 7 | @implementation NSView 8 | - (id)initWithView:(id)realView { 9 | *(NSView *)self = *(NSView *)realView; // expected-error {{cannot assign to class object}} 10 | } 11 | @end 12 | 13 | -------------------------------------------------------------------------------- /examples/SemaObjC/diagnose_if.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -verify -fno-builtin 2 | 3 | _Static_assert(__has_feature(attribute_diagnose_if_objc), "feature check failed?"); 4 | 5 | #define _diagnose_if(...) __attribute__((diagnose_if(__VA_ARGS__))) 6 | 7 | @interface I 8 | -(void)meth _diagnose_if(1, "don't use this", "warning"); // expected-note 1{{from 'diagnose_if'}} 9 | @property (assign) id prop _diagnose_if(1, "don't use this", "warning"); // expected-note 2{{from 'diagnose_if'}} 10 | @end 11 | 12 | void test(I *i) { 13 | [i meth]; // expected-warning {{don't use this}} 14 | id o1 = i.prop; // expected-warning {{don't use this}} 15 | id o2 = [i prop]; // expected-warning {{don't use this}} 16 | } 17 | -------------------------------------------------------------------------------- /examples/SemaObjC/direct-synthesized-ivar-access.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | // rdar://8673791 4 | // rdar://9943851 5 | 6 | @interface I { 7 | } 8 | 9 | @property int IVAR; 10 | - (int) OK; 11 | @end 12 | 13 | @implementation I 14 | - (int) Meth { return _IVAR; } 15 | - (int) OK { return self.IVAR; } 16 | @end 17 | -------------------------------------------------------------------------------- /examples/SemaObjC/dllexport.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple i686-windows -fdeclspec -fsyntax-only -verify %s 2 | 3 | __declspec(dllexport) typedef int typedef1; 4 | // expected-warning@-1{{'dllexport' attribute only applies to functions, variables, classes, and Objective-C interfaces}} 5 | typedef __declspec(dllexport) int typedef2; 6 | // expected-warning@-1{{'dllexport' attribute only applies to}} 7 | typedef int __declspec(dllexport) typedef3; 8 | // expected-warning@-1{{'dllexport' attribute only applies to}} 9 | typedef __declspec(dllexport) void (*FunTy)(); 10 | // expected-warning@-1{{'dllexport' attribute only applies to}} 11 | enum __declspec(dllexport) E { Val }; 12 | // expected-warning@-1{{'dllexport' attribute only applies to}} 13 | struct __declspec(dllexport) Record {}; 14 | // expected-warning@-1{{'dllexport' attribute only applies to}} 15 | 16 | __declspec(dllexport) 17 | __attribute__((__objc_root_class__)) 18 | @interface NSObject 19 | @end 20 | 21 | __declspec(dllexport) 22 | @interface I : NSObject 23 | - (void)method; 24 | @end 25 | 26 | @implementation I 27 | - (void)method { 28 | } 29 | @end 30 | 31 | -------------------------------------------------------------------------------- /examples/SemaObjC/dllimport.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple i686-windows -fdeclspec -fsyntax-only -verify %s 2 | 3 | __declspec(dllimport) typedef int typedef1; 4 | // expected-warning@-1{{'dllimport' attribute only applies to functions, variables, classes, and Objective-C interfaces}} 5 | typedef __declspec(dllimport) int typedef2; 6 | // expected-warning@-1{{'dllimport' attribute only applies to}} 7 | typedef int __declspec(dllimport) typedef3; 8 | // expected-warning@-1{{'dllimport' attribute only applies to}} 9 | typedef __declspec(dllimport) void (*FunTy)(); 10 | // expected-warning@-1{{'dllimport' attribute only applies to}} 11 | enum __declspec(dllimport) E { Val }; 12 | // expected-warning@-1{{'dllimport' attribute only applies to}} 13 | struct __declspec(dllimport) Record {}; 14 | // expected-warning@-1{{'dllimport' attribute only applies to}} 15 | 16 | __declspec(dllimport) 17 | __attribute__((__objc_root_class__)) 18 | @interface NSObject 19 | @end 20 | 21 | __declspec(dllimport) 22 | @interface I : NSObject 23 | - (void)method; 24 | @end 25 | 26 | @implementation I 27 | - (void)method { 28 | } 29 | @end 30 | 31 | -------------------------------------------------------------------------------- /examples/SemaObjC/duplicate-ivar-check.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @interface B1 { 4 | @public 5 | double fill_B; // expected-note {{previous declaration is here}} 6 | unsigned : 0; 7 | } 8 | @end 9 | 10 | @interface B : B1 { 11 | @public 12 | int one; // expected-note {{previous declaration is here}} 13 | int one; // expected-error {{duplicate member 'one'}} 14 | unsigned : 0; 15 | } 16 | @end 17 | 18 | @interface A : B { 19 | @public 20 | int fill_B; // expected-error {{duplicate member 'fill_B'}} 21 | } 22 | @end 23 | -------------------------------------------------------------------------------- /examples/SemaObjC/duplicate-ivar-in-class-extension.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @interface Root @end 4 | 5 | @interface SuperClass : Root 6 | { 7 | int iSuper; // expected-note {{previous declaration is here}} 8 | } 9 | @end 10 | 11 | @interface SubClass : SuperClass { 12 | int ivar; // expected-error {{duplicate member 'ivar'}} 13 | int another_ivar; // expected-error {{duplicate member 'another_ivar'}} 14 | int iSuper; // expected-error {{duplicate member 'iSuper'}} 15 | } 16 | @end 17 | 18 | @interface SuperClass () { 19 | int ivar; // expected-note {{previous declaration is here}} 20 | } 21 | @end 22 | 23 | @interface Root () { 24 | int another_ivar; // expected-note {{previous declaration is here}} 25 | } 26 | @end 27 | 28 | @implementation SubClass 29 | -(int) method { 30 | return self->ivar; // would be ambiguous if the duplicate ivar were allowed 31 | } 32 | @end 33 | -------------------------------------------------------------------------------- /examples/SemaObjC/duplicate-property-class-extension.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // rdar://7629420 3 | 4 | @interface Foo 5 | @property (readonly) char foo; 6 | @property (readwrite) char bar; // expected-note {{property declared here}} 7 | @end 8 | 9 | @interface Foo () 10 | @property (readwrite) char foo; // expected-note 2 {{property declared here}} 11 | @property (readwrite) char NewProperty; // expected-note 2 {{property declared here}} 12 | @property (readwrite) char bar; // expected-error{{illegal redeclaration of 'readwrite' property in class extension 'Foo' (perhaps you intended this to be a 'readwrite' redeclaration of a 'readonly' public property?)}} 13 | @end 14 | 15 | @interface Foo () 16 | @property (readwrite) char foo; // expected-error {{property has a previous declaration}} 17 | @property (readwrite) char NewProperty; // expected-error {{property has a previous declaration}} 18 | @end 19 | 20 | @interface Foo () 21 | @property (readonly) char foo; // expected-error {{property has a previous declaration}} 22 | @property (readwrite) char NewProperty; // expected-error {{property has a previous declaration}} 23 | @end 24 | 25 | -------------------------------------------------------------------------------- /examples/SemaObjC/duplicate-property.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @interface Foo { 4 | id x; 5 | } 6 | @property (nonatomic, retain) id x; // expected-note{{property declared here}} 7 | @property (nonatomic, retain) id x; // expected-error{{property has a previous declaration}} 8 | @end 9 | -------------------------------------------------------------------------------- /examples/SemaObjC/dynamic-direct-properties.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wselector-type-mismatch %s 2 | 3 | __attribute__((objc_root_class)) 4 | @interface Foo 5 | @property() int dynamic_property; 6 | @property(direct) int direct_property; // expected-note {{previous declaration is here}} 7 | @end 8 | 9 | @implementation Foo 10 | @dynamic dynamic_property; 11 | @dynamic direct_property; // expected-error {{direct property cannot be @dynamic}} 12 | @end 13 | 14 | @interface Foo (Bar) 15 | @property() int dynamic_category_property; 16 | @property(direct) int direct_category_property; // expected-note {{previous declaration is here}} 17 | @end 18 | 19 | @implementation Foo (Bar) 20 | @dynamic dynamic_category_property; 21 | @dynamic direct_category_property; // expected-error {{direct property cannot be @dynamic}} 22 | @end 23 | -------------------------------------------------------------------------------- /examples/SemaObjC/encode-typeof-test.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // rdar://16655340 3 | @protocol X, Y, Z; 4 | @class Foo; 5 | 6 | @protocol Proto 7 | @end 8 | 9 | @interface Intf 10 | { 11 | id IVAR_x; 12 | id IVAR_xy; 13 | id IVAR_xyz; 14 | Foo *IVAR_Fooxyz; 15 | Class IVAR_Classx; 16 | } 17 | @end 18 | 19 | @implementation Intf 20 | @end 21 | 22 | int main() 23 | { 24 | int i; 25 | typeof(@encode(typeof(i))) e = @encode(typeof(Intf)); // expected-warning {{initializer-string for char array is too long}} 26 | } 27 | 28 | // rdar://9255564 29 | typedef short short8 __attribute__((ext_vector_type(8))); 30 | 31 | struct foo { 32 | char a; 33 | int b; 34 | long c; 35 | short8 d; 36 | int array[4]; 37 | short int bitfield1:5; 38 | unsigned short bitfield2:11; 39 | char *string; 40 | }; 41 | 42 | const char *RetEncode () { 43 | return @encode(struct foo); // expected-warning {{encoding of 'struct foo' type is incomplete because 'short8' (vector of 8 'short' values) component has unknown encoding}} 44 | } 45 | 46 | -------------------------------------------------------------------------------- /examples/SemaObjC/enhanced-proto-2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | 4 | @protocol MyProto1 5 | @optional 6 | - (void) FOO; 7 | @optional 8 | - (void) FOO1; 9 | @optional 10 | - (void) REQ; 11 | @optional 12 | @end 13 | 14 | @interface MyProto2 15 | - (void) FOO2; 16 | - (void) FOO3; 17 | @end 18 | 19 | @implementation MyProto2 20 | - (void) FOO2{} 21 | - (void) FOO3{} 22 | @end 23 | -------------------------------------------------------------------------------- /examples/SemaObjC/err-ivar-access-in-class-method.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -x objective-c -fsyntax-only -verify -Wno-objc-root-class %s 2 | // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s 3 | // rdar://10593227 4 | 5 | @class UIWindow; 6 | 7 | @interface CNAppDelegate 8 | 9 | @property (strong, nonatomic) UIWindow *window; 10 | 11 | @end 12 | 13 | 14 | @interface CNAppDelegate () 15 | @property (nonatomic,retain) id foo; 16 | @end 17 | 18 | @implementation CNAppDelegate 19 | @synthesize foo; 20 | @synthesize window = _window; 21 | 22 | +(void)myClassMethod; 23 | { 24 | foo = 0; // expected-error {{instance variable 'foo' accessed in class method}} 25 | } 26 | @end 27 | -------------------------------------------------------------------------------- /examples/SemaObjC/error-implicit-property.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -Wno-objc-root-class -verify %s 2 | // rdar://11273060 3 | 4 | @interface I 5 | - (void) setP : (int)arg; 6 | @end 7 | 8 | @interface J 9 | - (int) P; 10 | @end 11 | 12 | @interface K @end 13 | 14 | @interface II @end 15 | 16 | @implementation II 17 | - (void) Meth : (I*) arg { 18 | arg.P++; // expected-error {{no getter method 'P' for increment of property}} 19 | --arg.P; // expected-error {{no getter method 'P' for decrement of property}} 20 | } 21 | - (void) Meth1 : (J*) arg { 22 | arg.P++; // expected-error {{no setter method 'setP:' for increment of property}} 23 | arg.P--; // expected-error {{no setter method 'setP:' for decrement of property}} 24 | } 25 | 26 | - (void) Meth2 : (K*) arg { 27 | arg.P++; // expected-error {{property 'P' not found on object of type 'K *'}} 28 | arg.P--; // expected-error {{property 'P' not found on object of type 'K *'}} 29 | } 30 | @end 31 | -------------------------------------------------------------------------------- /examples/SemaObjC/error-outof-scope-property-use.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s 3 | // rdar://13178483 4 | 5 | @class NSMutableDictionary; // expected-note {{receiver is instance of class declared here}} 6 | 7 | @interface LaunchdJobs 8 | 9 | @property (nonatomic,retain) NSMutableDictionary *uuids_jobs; // expected-note {{'_uuids_jobs' declared here}} 10 | 11 | @end 12 | 13 | @implementation LaunchdJobs 14 | 15 | -(void)job 16 | { 17 | 18 | [uuids_jobs objectForKey]; // expected-error {{use of undeclared identifier 'uuids_jobs'}} \ 19 | // expected-warning {{instance method '-objectForKey' not found}} 20 | } 21 | 22 | 23 | @end 24 | 25 | void 26 | doLaunchdJobCPU() 27 | { 28 | [uuids_jobs enumerateKeysAndObjectsUsingBlock]; // expected-error {{use of undeclared identifier 'uuids_jobs'}} 29 | } 30 | -------------------------------------------------------------------------------- /examples/SemaObjC/error-property-gc-attr.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple i386-apple-darwin9 -fobjc-gc -fsyntax-only -verify -Wno-objc-root-class %s 2 | // RUN: %clang_cc1 -x objective-c++ -triple i386-apple-darwin9 -fobjc-gc -fsyntax-only -verify -Wno-objc-root-class %s 3 | 4 | @interface INTF 5 | { 6 | id IVAR; // expected-note {{instance variable is declared here}} 7 | __weak id II; 8 | __weak id WID; 9 | id ID; 10 | __weak INTF* AWEAK; 11 | __weak INTF* WI; 12 | } 13 | @property (assign) __weak id pweak; 14 | @property (assign) __weak id WID; 15 | @property (assign) __strong id NOT; 16 | @property (assign) id ID; 17 | @property (assign) INTF* AWEAK; 18 | @property (assign) __weak INTF* WI; 19 | @end 20 | 21 | @implementation INTF 22 | @synthesize pweak=IVAR; // expected-error {{existing instance variable 'IVAR' for __weak property 'pweak' must be __weak}} 23 | @synthesize NOT=II; // expected-error {{existing instance variable 'II' for strong property 'NOT' may not be __weak}} 24 | @synthesize WID; 25 | @synthesize ID; 26 | @synthesize AWEAK; // expected-error {{existing instance variable 'AWEAK' for strong property 'AWEAK' may not be __weak}} 27 | @synthesize WI; 28 | @end 29 | -------------------------------------------------------------------------------- /examples/SemaObjC/externally-retained-no-arc.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -verify 2 | 3 | @interface NSWidget @end 4 | 5 | __attribute__((objc_externally_retained)) void f(NSWidget *p) { // expected-warning{{'objc_externally_retained' attribute ignored}} 6 | __attribute__((objc_externally_retained)) NSWidget *w; // expected-warning{{'objc_externally_retained' attribute ignored}} 7 | } 8 | -------------------------------------------------------------------------------- /examples/SemaObjC/flexible-array-arc.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s 2 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class -DNOARC %s 3 | #ifdef NOARC 4 | // expected-no-diagnostics 5 | #endif 6 | 7 | @interface RetainableArray { 8 | id flexible[]; 9 | #ifndef NOARC 10 | // expected-error@-2 {{ARC forbids flexible array members with retainable object type}} 11 | #endif 12 | } 13 | @end 14 | @implementation RetainableArray 15 | @end 16 | 17 | // Emit diagnostic only if have @implementation. 18 | @interface RetainableArrayWithoutImpl { 19 | id flexible[]; 20 | } 21 | @end 22 | 23 | // With ARC flexible array member objects can be only __unsafe_unretained 24 | @interface UnsafeUnretainedArray { 25 | __unsafe_unretained id flexible[]; 26 | } 27 | @end 28 | @implementation UnsafeUnretainedArray 29 | @end 30 | 31 | @interface NotObjCLifetimeTypeArray { 32 | char flexible[]; 33 | } 34 | @end 35 | @implementation NotObjCLifetimeTypeArray 36 | @end 37 | -------------------------------------------------------------------------------- /examples/SemaObjC/format-strings-system.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma clang system_header 3 | 4 | @class NSString; 5 | 6 | // Do not emit warnings when using NSLocalizedString 7 | extern NSString *GetLocalizedString(NSString *str); 8 | #define NSLocalizedString(key) GetLocalizedString(key) 9 | 10 | #define NSAssert(fmt, arg) NSLog(fmt, arg, 0, 0) 11 | -------------------------------------------------------------------------------- /examples/SemaObjC/forward-class-receiver.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @interface I 4 | + new; // expected-note {{method 'new' is used for the forward class}} 5 | @end 6 | Class isa; 7 | 8 | @class NotKnown; // expected-note{{forward declaration of class here}} 9 | 10 | void foo(NotKnown *n) { 11 | [isa new]; 12 | [NotKnown new]; /* expected-warning {{receiver 'NotKnown' is a forward class and corresponding}} */ 13 | } 14 | -------------------------------------------------------------------------------- /examples/SemaObjC/forward-class-redeclare.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // rdar://10733000 3 | 4 | @interface NSObject @end 5 | 6 | @protocol PLAssetContainer 7 | @property (readonly, nonatomic, retain) id assets; 8 | @end 9 | 10 | 11 | typedef NSObject PLAlbum; // expected-note {{previous definition is here}} 12 | 13 | @class PLAlbum; // expected-warning {{redefinition of forward class 'PLAlbum' of a typedef name of an object type is ignore}} 14 | 15 | @interface PLPhotoBrowserController 16 | { 17 | PLAlbum *_album; 18 | } 19 | @end 20 | 21 | @interface WPhotoViewController:PLPhotoBrowserController 22 | @end 23 | 24 | @implementation WPhotoViewController 25 | - (void)_prepareForContracting 26 | { 27 | (void)_album.assets; 28 | } 29 | @end 30 | -------------------------------------------------------------------------------- /examples/SemaObjC/forward-protocol-incomplete-impl-warn.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // rdar://12958878 3 | 4 | @interface NSObject @end 5 | 6 | @protocol DVTInvalidation 7 | - (void)invalidate; // expected-note {{method 'invalidate' declared here}} 8 | @property int Prop; // expected-note {{property declared here}} 9 | @end 10 | 11 | 12 | 13 | @protocol DVTInvalidation; 14 | 15 | @interface IBImageCatalogDocument : NSObject 16 | @end 17 | 18 | @implementation IBImageCatalogDocument // expected-warning {{auto property synthesis will not synthesize property 'Prop' declared in protocol 'DVTInvalidation'}} \ 19 | // expected-warning {{method 'invalidate' in protocol 'DVTInvalidation' not implemented}} 20 | @end // expected-note {{add a '@synthesize' directive}} 21 | -------------------------------------------------------------------------------- /examples/SemaObjC/gc-attributes.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-gc -fsyntax-only -verify %s 2 | 3 | @interface A 4 | @end 5 | 6 | void f0(__strong A**); // expected-note{{passing argument to parameter here}} 7 | 8 | void test_f0() { 9 | A *a; 10 | static __weak A *a2; 11 | f0(&a); 12 | f0(&a2); // expected-warning{{passing 'A *__weak *' to parameter of type 'A *__strong *' discards qualifiers}} 13 | } 14 | 15 | void f1(__weak A**); // expected-note{{passing argument to parameter here}} 16 | 17 | void test_f1() { 18 | A *a; 19 | __strong A *a2; 20 | f1(&a); 21 | f1(&a2); // expected-warning{{passing 'A *__strong *' to parameter of type 'A *__weak *' discards qualifiers}} 22 | } 23 | 24 | // These qualifiers should silently expand to nothing in GC mode. 25 | void test_unsafe_unretained(__unsafe_unretained id *x) {} 26 | void test_autoreleasing(__autoreleasing id *x) {} 27 | -------------------------------------------------------------------------------- /examples/SemaObjC/generic-selection.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | __attribute__((objc_root_class)) 5 | @interface Root { 6 | Class isa; 7 | } 8 | @end 9 | 10 | @interface A 11 | @property (strong) id x; 12 | @end 13 | 14 | // rdar://13193560 15 | void test0(A *a) { 16 | int kind = _Generic(a.x, id : 0, int : 1, float : 2); 17 | } 18 | -------------------------------------------------------------------------------- /examples/SemaObjC/getter-setter-defined-in-category-of-parent.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | 4 | @interface MyParent { 5 | int X; 6 | } 7 | @end 8 | @implementation MyParent 9 | @end 10 | 11 | @interface MyParent(AA) { 12 | } 13 | @end 14 | @implementation MyParent (AA) 15 | - (void) setX: (int)in {X = in - 2;} 16 | - (int) X {return X;} 17 | @end 18 | 19 | @interface MyClass : MyParent 20 | @end 21 | @implementation MyClass 22 | @end 23 | 24 | int foo(MyClass *o) { 25 | o.X = 2; 26 | return o.X; 27 | } -------------------------------------------------------------------------------- /examples/SemaObjC/ibaction.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -Wno-objc-root-class %s 2 | 3 | @interface Foo 4 | { 5 | __attribute__((iboutlet)) id myoutlet; 6 | } 7 | + (void) __attribute__((ibaction)) myClassMethod:(id)msg; // expected-warning{{'ibaction' attribute only applies to Objective-C instance methods}} 8 | - (void) __attribute__((ibaction)) myMessage:(id)msg; 9 | @end 10 | 11 | @implementation Foo 12 | + (void) __attribute__((ibaction)) myClassMethod:(id)msg {} // expected-warning{{'ibaction' attribute only applies to Objective-C instance methods}} 13 | // Normally attributes should not be attached to method definitions, but 14 | // we allow 'ibaction' to be attached because it can be expanded from 15 | // the IBAction macro. 16 | - (void) __attribute__((ibaction)) myMessage:(id)msg {} // no-warning 17 | @end 18 | -------------------------------------------------------------------------------- /examples/SemaObjC/id_builtin.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -fsyntax-only -verify 2 | // expected-no-diagnostics 3 | 4 | // id is now builtin. There should be no errors. 5 | id obj; 6 | 7 | @interface Foo 8 | 9 | - defaultToId; 10 | 11 | @end 12 | -------------------------------------------------------------------------------- /examples/SemaObjC/ignore-qualifier-on-qualified-id.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify %s 3 | // expected-no-diagnostics 4 | // rdar://10667659 5 | 6 | @protocol NSCopying @end 7 | 8 | @interface NSString 9 | @end 10 | 11 | void takeId(id test) {} 12 | 13 | void takeCopyableId(id test) {} 14 | 15 | id Test () { 16 | NSString const *constantString = @"Test"; 17 | takeId(constantString); 18 | takeCopyableId(constantString); 19 | id ID = constantString; 20 | id IDQNSCopying = constantString; 21 | return constantString; 22 | } 23 | -------------------------------------------------------------------------------- /examples/SemaObjC/ignore-weakimport-method.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | @interface foo 4 | + (void) cx __attribute__((weak_import)); 5 | - (void) x __attribute__((weak_import)); 6 | @end 7 | 8 | -------------------------------------------------------------------------------- /examples/SemaObjC/incompatible-protocol-qualified-types.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -pedantic -fsyntax-only -verify %s 2 | 3 | @protocol MyProto1 4 | @end 5 | 6 | @protocol MyProto2 7 | @end 8 | 9 | @interface INTF @end 10 | 11 | INTF * Func(INTF *p2) // expected-note{{passing argument to parameter 'p2' here}} 12 | { 13 | return p2; 14 | } 15 | 16 | 17 | INTF * Func1(INTF *p2) 18 | { 19 | return p2; 20 | } 21 | 22 | INTF * Func2(INTF *p2) 23 | { 24 | Func(p2); // expected-warning {{incompatible pointer types passing 'INTF *' to parameter of type 'INTF *'}} 25 | return p2; // expected-warning {{incompatible pointer types returning 'INTF *' from a function with result type 'INTF *'}} 26 | } 27 | 28 | 29 | 30 | INTF * Func3(INTF *p2) 31 | { 32 | return p2; // expected-warning {{incompatible pointer types returning 'INTF *' from a function with result type 'INTF *'}} 33 | } 34 | 35 | 36 | INTF * Func4(INTF *p2) 37 | { 38 | return p2; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /examples/SemaObjC/inst-method-lookup-in-root.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @protocol P 4 | - (id) inst_in_proto; 5 | @end 6 | 7 | @interface Object

8 | - (id) inst_in_root; 9 | @end 10 | 11 | @interface Base 12 | @end 13 | 14 | @interface Derived: Base 15 | - (id)starboard; 16 | @end 17 | 18 | void foo(void) { 19 | Class receiver; 20 | 21 | [Derived starboard]; // expected-warning {{method '+starboard' not found}} 22 | 23 | [receiver starboard]; // expected-warning {{instance method 'starboard' is being used on 'Class'}} 24 | [receiver inst_in_root]; // Ok! 25 | [receiver inst_in_proto]; // Ok! 26 | } 27 | 28 | -------------------------------------------------------------------------------- /examples/SemaObjC/integer-overflow.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -Wno-objc-root-class -fsyntax-only -verify %s 2 | 3 | @interface Foo 4 | @end 5 | 6 | @implementation Foo 7 | - (int)add:(int)a with:(int)b { 8 | return a + b; 9 | } 10 | 11 | - (void)testIntegerOverflows { 12 | // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}} 13 | (void)[self add:0 with:4608 * 1024 * 1024]; 14 | 15 | // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}} 16 | (void)[self add:0 with:[self add:4608 * 1024 * 1024 with:0]]; 17 | } 18 | @end 19 | -------------------------------------------------------------------------------- /examples/SemaObjC/interface-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple i386-apple-darwin9 -fobjc-runtime=macosx-fragile-10.5 %s -fsyntax-only -verify 2 | // rdar://5957506 3 | 4 | @interface NSWhatever : 5 | NSObject // expected-error {{cannot find interface declaration for 'NSObject'}} 6 | // expected-error {{no type or protocol named 'NSCopying'}} 7 | @end 8 | 9 | 10 | // rdar://6095245 11 | @interface A 12 | { 13 | int x 14 | } // expected-error {{expected ';' at end of declaration list}} 15 | @end 16 | 17 | 18 | // rdar://4304469 19 | @interface INT1 20 | @end 21 | 22 | void test2() { 23 | // rdar://6827200 24 | INT1 b[3]; // expected-error {{array of interface 'INT1' is invalid (probably should be an array of pointers)}} 25 | INT1 *c = &b[0]; 26 | ++c; 27 | } 28 | 29 | 30 | // rdar://6611778 31 | @interface FOO // expected-note {{previous definition is here}} 32 | - (void)method; 33 | @end 34 | 35 | @interface FOO // expected-error {{duplicate interface definition for class 'FOO'}} 36 | - (void)method2; 37 | @end 38 | 39 | -------------------------------------------------------------------------------- /examples/SemaObjC/interface-layout-2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -fsyntax-only -verify 2 | // expected-no-diagnostics 3 | @interface A 4 | { 5 | int ivar; 6 | } 7 | @end 8 | 9 | @interface B : A 10 | - (int)ivar; 11 | @end 12 | 13 | @implementation B 14 | - (int)ivar { 15 | return ivar; 16 | } 17 | @end 18 | -------------------------------------------------------------------------------- /examples/SemaObjC/interface-layout.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -fsyntax-only -verify -triple i386-apple-darwin9 -fobjc-runtime=macosx-fragile-10.5 2 | // expected-no-diagnostics 3 | typedef struct objc_object {} *id; 4 | typedef signed char BOOL; 5 | typedef unsigned int NSUInteger; 6 | typedef struct _NSZone NSZone; 7 | 8 | @protocol NSObject 9 | - (BOOL) isEqual:(id) object; 10 | @end 11 | 12 | @protocol NSCopying 13 | - (id) copyWithZone:(NSZone *) zone; 14 | @end 15 | 16 | @interface NSObject < NSObject > {} 17 | @end 18 | 19 | extern id NSAllocateObject (Class aClass, NSUInteger extraBytes, NSZone * zone); 20 | 21 | @interface MyClassBase : NSObject < NSCopying > {} 22 | @end 23 | 24 | @interface MyClassDirectNode : MyClassBase < NSCopying > 25 | { 26 | @public NSUInteger attributeRuns[((1024 - 16 - sizeof (MyClassBase)) / (sizeof (NSUInteger) + sizeof (void *)))]; 27 | } 28 | @end 29 | -------------------------------------------------------------------------------- /examples/SemaObjC/interface-scope.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | @interface I1 { 5 | @private 6 | int x; 7 | struct { 8 | unsigned int x : 3; 9 | unsigned int y : 3; 10 | } flags; 11 | int y; 12 | } 13 | @end 14 | -------------------------------------------------------------------------------- /examples/SemaObjC/interface-tu-variable.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @interface XX 4 | int x; // expected-error {{cannot declare variable inside @interface or @protocol}} 5 | int one=1; // expected-error {{cannot declare variable inside @interface or @protocol}} 6 | @end 7 | 8 | @protocol PPP 9 | int ddd; // expected-error {{cannot declare variable inside @interface or @protocol}} 10 | @end 11 | 12 | @interface XX(CAT) 13 | char * III; // expected-error {{cannot declare variable inside @interface or @protocol}} 14 | extern int OK; 15 | @end 16 | 17 | @interface XX() 18 | char * III2; // expected-error {{cannot declare variable inside @interface or @protocol}} 19 | extern int OK2; 20 | @end 21 | 22 | 23 | int main( int argc, const char *argv[] ) { 24 | return x+one; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /examples/SemaObjC/invalid-receiver.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | typedef struct NotAClass { 4 | int a, b; 5 | } NotAClass; 6 | 7 | void foo() { 8 | [NotAClass nonexistent_method]; // expected-error {{receiver type 'NotAClass' (aka 'struct NotAClass') is not an Objective-C class}} 9 | } 10 | -------------------------------------------------------------------------------- /examples/SemaObjC/invalid-typename.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @class NSString, NSArray; 4 | 5 | @protocol ISyncSessionCallback 6 | - (oneway void)clientWithId:(bycopy NSString *)clientId 7 | canBeginSyncingPlanWithId:(bycopy NSString *)planId 8 | syncModes:(bycopy NSArray /* ISDSyncState */ *)syncModes 9 | entities:(bycopy NSArray /* ISDEntity */ *)entities 10 | truthPullers:(bycopy NSDictionary /* NSString -> [NSString] */ *)truthPullers; // expected-error {{expected a type}} 11 | @end 12 | 13 | -------------------------------------------------------------------------------- /examples/SemaObjC/ivar-access-package.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | typedef unsigned char BOOL; 5 | 6 | @interface NSObject { 7 | id isa; 8 | } 9 | +new; 10 | +alloc; 11 | -init; 12 | -autorelease; 13 | @end 14 | 15 | @interface NSAutoreleasePool : NSObject 16 | - drain; 17 | @end 18 | 19 | @interface A : NSObject { 20 | @package 21 | id object; 22 | } 23 | @end 24 | 25 | @interface B : NSObject 26 | - (BOOL)containsSelf:(A*)a; 27 | @end 28 | 29 | @implementation A 30 | @end 31 | 32 | @implementation B 33 | - (BOOL)containsSelf:(A*)a { 34 | return a->object == self; 35 | } 36 | @end 37 | 38 | void NSLog(id, ...); 39 | 40 | int main (int argc, const char * argv[]) { 41 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 42 | A *a = [[A new] autorelease]; 43 | B *b = [[B new] autorelease]; 44 | NSLog(@"%s", [b containsSelf:a] ? "YES" : "NO"); 45 | [pool drain]; 46 | return 0; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /examples/SemaObjC/ivar-in-class-extension-error.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fobjc-runtime=macosx-fragile-10.5 -fsyntax-only -verify %s 2 | // rdar://6812436 3 | 4 | @interface A @end 5 | 6 | @interface A () { 7 | int _p0; // expected-error {{instance variables may not be placed in class extension}} 8 | } 9 | @property int p0; 10 | @end 11 | 12 | @interface A(CAT) { 13 | int _p1; // expected-error {{instance variables may not be placed in categories}} 14 | } 15 | @end 16 | -------------------------------------------------------------------------------- /examples/SemaObjC/ivar-in-implementations.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | @interface Super @end 4 | 5 | @interface INTFSTANDALONE : Super 6 | { 7 | id IVAR; // expected-note {{previous definition is here}} 8 | } 9 | 10 | @end 11 | 12 | @implementation INTFSTANDALONE : Super // expected-warning {{class implementation may not have super class}} 13 | { 14 | id PRIV_IVAR; 15 | @protected 16 | id PRTCTD; 17 | @private 18 | id IVAR3; 19 | int IVAR; // expected-error {{instance variable is already declared}} 20 | @public 21 | id IVAR4; 22 | } 23 | @end 24 | 25 | @interface Base @end 26 | 27 | @implementation Base { 28 | int ivar1; 29 | @public 30 | int ivar2; 31 | } 32 | @end 33 | 34 | id fn1(INTFSTANDALONE *b) { return b->PRIV_IVAR; } // expected-error {{instance variable 'PRIV_IVAR' is private}} 35 | 36 | id fn2(INTFSTANDALONE *b) { return b->PRTCTD; } // expected-error {{instance variable 'PRTCTD' is protected}} 37 | 38 | id fn4(INTFSTANDALONE *b) { return b->IVAR4; } 39 | 40 | -------------------------------------------------------------------------------- /examples/SemaObjC/ivar-lookup-resolution-builtin.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // pr5986 3 | 4 | @interface Test { 5 | int index; 6 | } 7 | - (int) index; 8 | + (int) ClassMethod; 9 | @end 10 | 11 | @implementation Test 12 | - (int) index 13 | { 14 | return index; 15 | } 16 | + (int) ClassMethod 17 | { 18 | return index; // expected-error {{instance variable 'index' accessed in class method}} 19 | } 20 | @end 21 | 22 | @interface Test1 { 23 | } 24 | - (int) InstMethod; 25 | + (int) ClassMethod; 26 | @end 27 | 28 | @implementation Test1 29 | - (int) InstMethod 30 | { 31 | return index; // expected-warning {{implicitly declaring library function 'index'}} \ 32 | // expected-note {{include the header or explicitly provide a declaration for 'index'}} \ 33 | // expected-warning {{incompatible pointer to integer conversion returning}} 34 | } 35 | + (int) ClassMethod 36 | { 37 | return index; // expected-warning {{incompatible pointer to integer conversion returning}} 38 | } 39 | @end 40 | 41 | -------------------------------------------------------------------------------- /examples/SemaObjC/ivar-sem-check-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | struct S; // expected-note{{forward declaration of 'struct S'}} 4 | typedef int FOO(); 5 | 6 | @interface INTF 7 | { 8 | struct F {} JJ; 9 | int arr[]; // expected-error {{flexible array member 'arr' with type 'int []' is not at the end of class}} 10 | struct S IC; // expected-error {{field has incomplete type}} 11 | // expected-note@-1 {{next instance variable declaration is here}} 12 | struct T { // expected-note {{previous definition is here}} 13 | struct T {} X; // expected-error {{nested redefinition of 'T'}} 14 | }YYY; 15 | FOO BADFUNC; // expected-error {{field 'BADFUNC' declared as a function}} 16 | int kaka; // expected-note {{previous declaration is here}} 17 | int kaka; // expected-error {{duplicate member 'kaka'}} 18 | char ch[]; 19 | } 20 | @end 21 | -------------------------------------------------------------------------------- /examples/SemaObjC/ivar-sem-check-2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @interface Super { 4 | id value2; // expected-note {{previously declared 'value2' here}} 5 | } 6 | @property(retain) id value; 7 | @property(retain) id value1; 8 | @property(retain) id prop; 9 | @end 10 | 11 | @interface Sub : Super 12 | { 13 | id value; 14 | } 15 | @end 16 | 17 | @implementation Sub 18 | @synthesize value; // expected-note {{previous use is here}} 19 | @synthesize value1=value; // expected-error {{synthesized properties 'value1' and 'value' both claim instance variable 'value'}} 20 | @synthesize prop=value2; // expected-error {{property 'prop' attempting to use instance variable 'value2' declared in super class 'Super'}} 21 | @end 22 | 23 | 24 | -------------------------------------------------------------------------------- /examples/SemaObjC/legacy-implementation-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | @implementation INTF // expected-warning {{cannot find interface declaration for 'INTF'}} 4 | @end 5 | 6 | INTF* pi; 7 | 8 | INTF* FUNC() 9 | { 10 | return pi; 11 | } 12 | -------------------------------------------------------------------------------- /examples/SemaObjC/matrix-type-operators.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -fenable-matrix %s 2 | 3 | struct Foo {}; 4 | __attribute__((objc_root_class)) 5 | @interface FooValue 6 | @property struct Foo value; 7 | @end 8 | 9 | typedef double double4x4 __attribute__((matrix_type(4, 4))); 10 | 11 | // Check that we generate proper error messages for invalid placeholder types. 12 | // 13 | double test_index_placeholders(double4x4 m, FooValue *iv) { 14 | return m[iv.value][iv.value]; 15 | // expected-error@-1 {{matrix row index is not an integer}} 16 | // expected-error@-2 {{matrix column index is not an integer}} 17 | } 18 | 19 | double test_base_and_index_placeholders(FooValue *m, FooValue *iv) { 20 | return m.value[iv.value][iv.value]; 21 | // expected-error@-1 {{subscripted value is not an array, pointer, or vector}} 22 | } 23 | -------------------------------------------------------------------------------- /examples/SemaObjC/method-arg-qualifier-warning.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | typedef signed char BOOL; 4 | 5 | @interface NSString 6 | - (BOOL)isEqualToString:(NSString *)aString; // expected-note 2{{passing argument to parameter 'aString' here}} 7 | @end 8 | 9 | static const NSString * Identifier1 = @"Identifier1"; 10 | static NSString const * Identifier2 = @"Identifier2"; 11 | static NSString * const Identifier3 = @"Identifier3"; 12 | 13 | int main () { 14 | 15 | [@"Identifier1" isEqualToString:Identifier1]; // expected-warning {{sending 'const NSString *' to parameter of type 'NSString *' discards qualifiers}} 16 | [@"Identifier2" isEqualToString:Identifier2]; // expected-warning {{sending 'const NSString *' to parameter of type 'NSString *' discards qualifiers}} 17 | [@"Identifier3" isEqualToString:Identifier3]; 18 | return 0; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /examples/SemaObjC/method-def-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -Wmethod-signatures -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | @interface foo 4 | - (int)meth; 5 | @end 6 | 7 | @implementation foo 8 | - (int) meth { return [self meth]; } 9 | @end 10 | 11 | // PR2708 12 | @interface MyClass 13 | +- (void)myMethod; // expected-error {{expected selector for Objective-C method}} 14 | - (vid)myMethod2; // expected-error {{expected a type}} 15 | @end 16 | 17 | @implementation MyClass 18 | - (void)myMethod { } 19 | - (vid)myMethod2 { } // expected-error {{expected a type}} 20 | 21 | @end 22 | 23 | 24 | @protocol proto; 25 | @protocol NSObject; 26 | 27 | //@protocol GrowlPluginHandler @end 28 | 29 | 30 | @interface SomeClass2 31 | - (int)myMethod1: (id) 32 | arg; // expected-note {{previous definition is here}} 33 | @end 34 | 35 | @implementation SomeClass2 36 | - (int)myMethod1: (id) 37 | arg { // expected-warning {{conflicting parameter types in implementation of 'myMethod1:': 'id' vs 'id'}} 38 | 39 | } 40 | @end 41 | -------------------------------------------------------------------------------- /examples/SemaObjC/method-def-2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -ast-print %s 2 | extern void abort(void); 3 | #define CHECK_IF(expr) if(!(expr)) abort() 4 | 5 | static double d = 4.5920234e2; 6 | 7 | @interface Foo 8 | -(void) brokenType: (int)x floatingPoint: (double)y; 9 | @end 10 | 11 | 12 | @implementation Foo 13 | -(void) brokenType: (int)x floatingPoint: (double)y 14 | { 15 | CHECK_IF(x == 459); 16 | CHECK_IF(y == d); 17 | } 18 | @end 19 | 20 | -------------------------------------------------------------------------------- /examples/SemaObjC/method-encoding-2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s 2 | // TODO: We don't support rewrite of method definitions 3 | 4 | @interface Intf 5 | - (in out bycopy id) address:(byref inout void *)location with:(out oneway unsigned **)arg2; 6 | - (id) another:(void *)location with:(unsigned **)arg2; 7 | @end 8 | 9 | @implementation Intf 10 | - (in out bycopy id) address:(byref inout void *)location with:(out oneway unsigned **)arg2{ return 0; } 11 | - (id) another:(void *)location with:(unsigned **)arg2 { return 0; } 12 | @end 13 | -------------------------------------------------------------------------------- /examples/SemaObjC/method-in-class-extension-impl.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | // rdar://8530080 4 | 5 | @protocol ViewDelegate @end 6 | 7 | @interface NSTextView 8 | - (id )delegate; 9 | @end 10 | 11 | @interface FooTextView : NSTextView 12 | @end 13 | 14 | @interface FooTextView() 15 | - (id)delegate; 16 | @end 17 | 18 | @implementation FooTextView 19 | - (id)delegate {return 0; } 20 | @end 21 | 22 | -------------------------------------------------------------------------------- /examples/SemaObjC/method-lookup-5.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // rdar://8592156 3 | 4 | typedef struct objc_class *Class; 5 | @interface A 6 | -(Class) foo; 7 | @end 8 | 9 | void f0(A *a) { int x = [[a foo] baz]; } // expected-warning {{method '+baz' not found (return type defaults to 'id')}} \ 10 | // expected-warning {{ncompatible pointer to integer conversion initializing 'int' with an expression of type 'id'}} 11 | -------------------------------------------------------------------------------- /examples/SemaObjC/method-no-context.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | - im0 { // expected-error{{missing context for method declaration}} 4 | int a; return 0; 5 | -------------------------------------------------------------------------------- /examples/SemaObjC/method-not-defined.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @interface Foo // expected-note {{receiver is instance of class declared here}} 4 | @end 5 | 6 | void test() { 7 | Foo *fooObj; 8 | id obj; 9 | 10 | [[Foo alloc] init]; // expected-warning {{class method '+alloc' not found (return type defaults to 'id')}} expected-warning {{instance method '-init' not found (return type defaults to 'id')}} 11 | [fooObj notdefined]; // expected-warning {{instance method '-notdefined' not found (return type defaults to 'id')}} 12 | [obj whatever:1 :2 :3]; // expected-warning {{instance method '-whatever:::' not found (return type defaults to 'id')}} 13 | } 14 | -------------------------------------------------------------------------------- /examples/SemaObjC/method-redecls-invalid-interface.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wdocumentation -Wno-objc-root-class %s 2 | // rdar://29220965 3 | 4 | @interface InvalidInterface { // expected-note {{previous definition is here}} 5 | int *_property; 6 | } 7 | 8 | @end 9 | 10 | /*! 11 | */ 12 | 13 | @interface InvalidInterface // expected-error {{duplicate interface definition for class 'InvalidInterface'}} 14 | @property int *property; 15 | 16 | -(void) method; 17 | @end 18 | 19 | @implementation InvalidInterface 20 | -(void) method { } 21 | @end 22 | -------------------------------------------------------------------------------- /examples/SemaObjC/method-return-void.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -Wmethod-signatures -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | @interface Test 4 | - (int)foo; 5 | @end 6 | 7 | @implementation Test 8 | - (int)foo { return; } // expected-error {{non-void method 'foo' should return a value}} 9 | @end 10 | -------------------------------------------------------------------------------- /examples/SemaObjC/method-typecheck-2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @protocol P 4 | - (void) doSomethingInProtocol: (float) x; // expected-note {{previous definition is here}} 5 | + (void) doSomethingClassyInProtocol: (float) x; // expected-note {{previous definition is here}} 6 | - (void) doNothingInProtocol : (float) x; 7 | + (void) doNothingClassyInProtocol : (float) x; 8 | @end 9 | 10 | @interface I

11 | - (void) doSomething: (float) x; // expected-note {{previous definition is here}} 12 | + (void) doSomethingClassy: (int) x; // expected-note {{previous definition is here}} 13 | @end 14 | 15 | @interface Bar : I 16 | @end 17 | 18 | @implementation Bar 19 | - (void) doSomething: (int) x {} // expected-warning {{conflicting parameter types}} 20 | + (void) doSomethingClassy: (float) x{} // expected-warning {{conflicting parameter types}} 21 | - (void) doSomethingInProtocol: (id) x {} // expected-warning {{conflicting parameter types}} 22 | + (void) doSomethingClassyInProtocol: (id) x {} // expected-warning {{conflicting parameter types}} 23 | @end 24 | 25 | 26 | -------------------------------------------------------------------------------- /examples/SemaObjC/method-typecheck-3.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -Wmethod-signatures -fsyntax-only -verify %s 2 | 3 | @class B; 4 | @interface A 5 | - (B*)obj; 6 | - (B*)a; // expected-note {{previous definition is here}} 7 | - (void)takesA: (A*)a; // expected-note {{previous definition is here}} 8 | - (void)takesId: (id)a; // expected-note {{previous definition is here}} 9 | @end 10 | 11 | 12 | @interface B : A 13 | @end 14 | 15 | @implementation B 16 | - (id)obj {return self;} // 'id' overrides are white-listed? 17 | - (A*)a { return self;} // expected-warning {{conflicting return type in implementation of 'a'}} 18 | - (void)takesA: (B*)a // expected-warning {{conflicting parameter types in implementation of 'takesA:'}} 19 | {} 20 | - (void)takesId: (B*)a // expected-warning {{conflicting parameter types in implementation of 'takesId:'}} 21 | {} 22 | @end 23 | -------------------------------------------------------------------------------- /examples/SemaObjC/method-undef-extension-warn-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | @interface MyClass 4 | @end 5 | 6 | @protocol P 7 | - (void)Pmeth; 8 | - (void)Pmeth1; // expected-note {{method 'Pmeth1' declared here}} 9 | @end 10 | 11 | // Class extension 12 | @interface MyClass ()

13 | - (void)meth2; // expected-note {{method 'meth2' declared here}} 14 | @end 15 | 16 | // Add a category to test that clang does not emit warning for this method. 17 | @interface MyClass (Category) 18 | - (void)categoryMethod; 19 | @end 20 | 21 | @implementation MyClass // expected-warning {{method 'Pmeth1' in protocol 'P' not implemented}} \ 22 | // expected-warning {{method definition for 'meth2' not found}} 23 | - (void)Pmeth {} 24 | @end 25 | -------------------------------------------------------------------------------- /examples/SemaObjC/method-unused-attribute.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -Wunused-parameter -verify -Wno-objc-root-class %s 2 | 3 | // -Wunused-parameter ignores ObjC method parameters that are unused. 4 | 5 | // expected-no-diagnostics 6 | 7 | @interface INTF 8 | - (void) correct_use_of_unused: (void *) notice : (id)another_arg; 9 | - (void) will_warn_unused_arg: (void *) notice : (id)warn_unused; 10 | - (void) unused_attr_on_decl_ignored: (void *) __attribute__((unused)) will_warn; 11 | @end 12 | 13 | @implementation INTF 14 | - (void) correct_use_of_unused: (void *) __attribute__((unused)) notice : (id) __attribute__((unused)) newarg{ 15 | } 16 | - (void) will_warn_unused_arg: (void *) __attribute__((unused)) notice : (id)warn_unused {} 17 | - (void) unused_attr_on_decl_ignored: (void *) will_warn{} 18 | @end 19 | 20 | -------------------------------------------------------------------------------- /examples/SemaObjC/method-warn-unused-attribute.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -Wunused-value -verify %s 2 | 3 | @interface INTF 4 | - (id) foo __attribute__((warn_unused_result)); 5 | - (void) garf __attribute__((warn_unused_result)); // expected-warning {{attribute 'warn_unused_result' cannot be applied to Objective-C method without return value}} 6 | - (int) fee __attribute__((warn_unused_result)); 7 | + (int) c __attribute__((warn_unused_result)); 8 | @end 9 | 10 | void foo(INTF *a) { 11 | [a garf]; 12 | [a fee]; // expected-warning {{ignoring return value of function declared with 'warn_unused_result' attribute}} 13 | [INTF c]; // expected-warning {{ignoring return value of function declared with 'warn_unused_result' attribute}} 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/SemaObjC/mismatched-undefined-method.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -Wno-deprecated-declarations -verify %s 2 | // rdar://11460990 3 | 4 | typedef unsigned int CGDirectDisplayID; 5 | 6 | @interface NSObject @end 7 | 8 | @interface BrightnessAssistant : NSObject {} 9 | - (void)BrightnessAssistantUnregisterForNotifications:(void*) observer; // expected-note {{previous definition is here}} 10 | @end 11 | @implementation BrightnessAssistant // expected-note {{implementation started here}} 12 | - (void)BrightnessAssistantUnregisterForNotifications:(CGDirectDisplayID) displayID, void* observer // expected-warning {{conflicting parameter types in implementation of 'BrightnessAssistantUnregisterForNotifications:': 'void *' vs 'CGDirectDisplayID'}} 13 | @end // expected-error {{expected method body}} // expected-error {{missing '@end'}} 14 | -------------------------------------------------------------------------------- /examples/SemaObjC/missing-atend-metadata.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | @interface I0 // expected-note {{receiver is instance of class declared here}} 4 | @end 5 | 6 | @implementation I0 // expected-note {{implementation started here}} 7 | - meth { return 0; } 8 | 9 | @interface I1 : I0 // expected-error {{missing '@end'}} 10 | @end 11 | 12 | @implementation I1 // expected-note {{implementation started here}} 13 | -(void) im0 { self = [super init]; } // expected-warning {{not found}} 14 | 15 | @interface I2 : I0 // expected-error {{missing '@end'}} 16 | - I2meth; 17 | @end 18 | 19 | @implementation I2 // expected-note {{implementation started here}} 20 | - I2meth { return 0; } 21 | 22 | @implementation I2(CAT) // expected-error 2 {{missing '@end'}} expected-note {{implementation started here}} 23 | -------------------------------------------------------------------------------- /examples/SemaObjC/missing-method-context.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -verify -fsyntax-only 2 | - (void)compilerTestAgainst; // expected-error {{missing context for method declaration}} 3 | 4 | void xx(); // expected-error {{expected method body}} 5 | -------------------------------------------------------------------------------- /examples/SemaObjC/missing-method-return-type.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -Wmissing-method-return-type -fsyntax-only -verify -Wno-objc-root-class %s 2 | // rdar://9615045 3 | 4 | @interface I 5 | - initWithFoo:(id)foo; // expected-warning {{method has no return type specified; defaults to 'id'}} 6 | @end 7 | 8 | @implementation I 9 | - initWithFoo:(id)foo { return 0; } // expected-warning {{method has no return type specified; defaults to 'id'}} 10 | @end 11 | 12 | -------------------------------------------------------------------------------- /examples/SemaObjC/multiple-method-names-in-class-self.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -Wobjc-multiple-method-names -x objective-c -verify %s 2 | // RUN: %clang_cc1 -Wobjc-multiple-method-names -x objective-c -verify -fobjc-arc %s 3 | // expected-no-diagnostics 4 | 5 | @interface NSObj 6 | 7 | + (instancetype) alloc; 8 | 9 | + (_Nonnull instancetype) globalObject; 10 | 11 | @end 12 | 13 | @interface SelfAllocReturn: NSObj 14 | 15 | - (instancetype)initWithFoo:(int)x; 16 | 17 | @end 18 | 19 | @interface SelfAllocReturn2: NSObj 20 | 21 | - (instancetype)initWithFoo:(SelfAllocReturn *)x; 22 | 23 | @end 24 | 25 | @implementation SelfAllocReturn 26 | 27 | - (instancetype)initWithFoo:(int)x { 28 | return self; 29 | } 30 | 31 | + (instancetype) thingWithFoo:(int)x { 32 | return [[self alloc] initWithFoo: x]; 33 | } 34 | 35 | + (void) initGlobal { 36 | (void)[[self globalObject] initWithFoo: 20]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /examples/SemaObjC/multiple-method-names.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -Wobjc-multiple-method-names -x objective-c %s -verify 2 | // PR22047 3 | 4 | @interface Face0 5 | - (void)foo:(float)i; // expected-note {{using}} 6 | @end 7 | 8 | @interface Face1 9 | - (void)foo:(int)i __attribute__((unavailable)); 10 | @end 11 | 12 | @interface Face2 13 | - (void)foo:(char)i; // expected-note {{also found}} 14 | @end 15 | 16 | void f(id i) { 17 | [i foo:4.0f]; // expected-warning {{multiple methods named 'foo:' found}} 18 | } 19 | 20 | -------------------------------------------------------------------------------- /examples/SemaObjC/multiple-property-deprecated-decl.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.11 -verify -Wno-objc-root-class %s 2 | // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -triple x86_64-apple-macosx10.11 -verify -Wno-objc-root-class %s 3 | // expected-no-diagnostics 4 | // rdar://20408445 5 | 6 | @protocol NSFileManagerDelegate @end 7 | 8 | @interface NSFileManager 9 | @property (assign) id delegate; 10 | @end 11 | 12 | @interface NSFontManager 13 | @property (assign) id delegate __attribute__((availability(macosx,introduced=10.0 ,deprecated=10.11,message="" "NSFontManager doesn't have any delegate method. This property should not be used."))); 14 | 15 | @end 16 | 17 | id Test20408445(id p) { 18 | return [p delegate]; 19 | } 20 | -------------------------------------------------------------------------------- /examples/SemaObjC/narrow-property-type-in-cont-class.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -x objective-c -fsyntax-only -verify %s 2 | // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify %s 3 | // rdar://10790488 4 | 5 | @interface NSArray @end 6 | 7 | @interface NSMutableArray : NSArray 8 | @end 9 | 10 | @interface GKTurnBasedMatchMakerKVO 11 | @property(nonatomic,readonly,retain) NSArray* outline; 12 | @property(nonatomic,readonly,retain) NSMutableArray* err_outline; // expected-note {{property declared here}} 13 | @end 14 | 15 | @interface GKTurnBasedMatchMakerKVO () 16 | @property(nonatomic,readwrite,retain) NSMutableArray* outline; 17 | @property(nonatomic,readwrite,retain) NSArray* err_outline; // expected-error {{type of property 'NSArray *' in class extension does not match property type in primary class}} 18 | @end 19 | 20 | -------------------------------------------------------------------------------- /examples/SemaObjC/nested-typedef-decl.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -x objective-c -fsyntax-only -verify -Wno-objc-root-class %s 2 | // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s 3 | // expected-no-diagnostics 4 | // rdar://10041908 5 | 6 | @interface Bar { 7 | struct _A *_hardlinkList; 8 | } 9 | @end 10 | @implementation Bar 11 | typedef struct _A { 12 | int dev; 13 | int inode; 14 | } A; 15 | 16 | - (void) idx:(int)idx ino:(int)ino dev:(int)dev 17 | { 18 | _hardlinkList[idx].inode = ino; 19 | _hardlinkList[idx].dev = dev; 20 | } 21 | @end 22 | 23 | -------------------------------------------------------------------------------- /examples/SemaObjC/no-gc-weak-test.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | @interface Subtask 4 | { 5 | id _delegate; 6 | } 7 | @property(nonatomic,readwrite,assign) id __weak delegate; // expected-error {{unsafe_unretained property 'delegate' may not also be declared __weak}} 8 | @end 9 | 10 | @implementation Subtask 11 | @synthesize delegate = _delegate; 12 | @end 13 | 14 | 15 | @interface PVSelectionOverlayView2 16 | { 17 | id __weak _selectionRect; // expected-error {{cannot create __weak reference because the current deployment target does not support weak references}} expected-error {{existing instance variable '_selectionRect' for property 'selectionRect' with assign attribute must be __unsafe_unretained}} 18 | } 19 | 20 | @property(assign) id selectionRect; // expected-note {{property declared here}} 21 | 22 | @end 23 | 24 | @implementation PVSelectionOverlayView2 25 | 26 | @synthesize selectionRect = _selectionRect; // expected-note {{property synthesized here}} 27 | @end 28 | 29 | -------------------------------------------------------------------------------- /examples/SemaObjC/no-ivar-in-interface-block.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class -Wobjc-interface-ivars %s 2 | // rdar://10763173 3 | 4 | @interface I 5 | { 6 | @protected int P_IVAR; // expected-warning {{declaration of instance variables in the interface is deprecated}} 7 | 8 | @public int PU_IVAR; // expected-warning {{declaration of instance variables in the interface is deprecated}} 9 | 10 | @private int PRV_IVAR; // expected-warning {{declaration of instance variables in the interface is deprecated}} 11 | } 12 | @end 13 | 14 | @interface I() 15 | { 16 | int I1; 17 | int I2; 18 | } 19 | @end 20 | 21 | @interface I() 22 | { 23 | int I3, I4; 24 | } 25 | @end 26 | 27 | @implementation I 28 | { 29 | int I5; 30 | int I6; 31 | } 32 | @end 33 | -------------------------------------------------------------------------------- /examples/SemaObjC/no-objc-exceptions.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | void f() { 4 | @throw @"Hello"; // expected-error {{cannot use '@throw' with Objective-C exceptions disabled}} 5 | } 6 | 7 | void g() { 8 | @try { // expected-error {{cannot use '@try' with Objective-C exceptions disabled}} 9 | f(); 10 | } @finally { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/SemaObjC/no-protocol-option-tests.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -Wno-protocol -verify -Wno-objc-root-class %s 2 | // rdar: // 7056600 3 | 4 | @protocol P 5 | - PMeth; 6 | @end 7 | 8 | // Test1 9 | @interface I

@end 10 | @implementation I @end // no warning with -Wno-protocol 11 | 12 | // Test2 13 | @interface C -PMeth; @end 14 | @interface C (Category)

@end 15 | @implementation C (Category) @end // no warning with -Wno-protocol 16 | 17 | // Test2 18 | @interface super - PMeth; @end 19 | @interface J : super

20 | - PMeth; // expected-note {{method 'PMeth' declared here}} 21 | @end 22 | @implementation J @end // expected-warning {{method definition for 'PMeth' not found}} 23 | 24 | // Test3 25 | @interface K : super

26 | @end 27 | @implementation K @end // no warning with -Wno-protocol 28 | 29 | // Test4 30 | @interface Root @end 31 | @interface L : Root

@end 32 | @implementation L @end // no warning with -Wno-protocol 33 | -------------------------------------------------------------------------------- /examples/SemaObjC/no-warn-qual-mismatch.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | // radar 7211563 4 | 5 | @interface X 6 | 7 | + (void)prototypeWithScalar:(int)aParameter; 8 | + (void)prototypeWithPointer:(void *)aParameter; 9 | 10 | @end 11 | 12 | @implementation X 13 | 14 | + (void)prototypeWithScalar:(const int)aParameter {} 15 | + (void)prototypeWithPointer:(void * const)aParameter {} 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /examples/SemaObjC/no-warn-synth-protocol-meth.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | 4 | @protocol CYCdef 5 | - (int)name; 6 | @end 7 | 8 | @interface JSCdef { 9 | int name; 10 | } 11 | 12 | @property (assign) int name; 13 | @end 14 | 15 | @implementation JSCdef 16 | @synthesize name; 17 | @end 18 | 19 | -------------------------------------------------------------------------------- /examples/SemaObjC/no-warn-unimpl-method.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | // This program tests that if class implements the forwardInvocation method, then 4 | // every method possible is implemented in the class and should not issue 5 | // warning of the "Method definition not found" kind. */ 6 | 7 | @interface NSObject 8 | @end 9 | 10 | @interface NSInvocation 11 | @end 12 | 13 | @interface NSProxy 14 | @end 15 | 16 | @protocol MyProtocol 17 | -(void) doSomething; 18 | @end 19 | 20 | @interface DestinationClass : NSObject 21 | -(void) doSomething; 22 | @end 23 | 24 | @implementation DestinationClass 25 | -(void) doSomething 26 | { 27 | } 28 | @end 29 | 30 | @interface MyProxy : NSProxy 31 | { 32 | DestinationClass *mTarget; 33 | } 34 | - (id) init; 35 | - (void)forwardInvocation:(NSInvocation *)anInvocation; 36 | @end 37 | 38 | @implementation MyProxy 39 | - (void)forwardInvocation:(NSInvocation *)anInvocation 40 | { 41 | } 42 | - (id) init { return 0; } 43 | @end 44 | -------------------------------------------------------------------------------- /examples/SemaObjC/no-warning-unavail-unimp.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | // rdar://9651605 4 | // rdar://12958191 5 | 6 | @interface Foo 7 | @property (getter=getVal) int val __attribute__((unavailable)); 8 | @property (getter=getVal) int val2 __attribute__((availability(macosx,unavailable))); 9 | - Method __attribute__((unavailable)); 10 | + CMethod __attribute__((unavailable)); 11 | @end 12 | 13 | @implementation Foo 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /examples/SemaObjC/nonnull.h: -------------------------------------------------------------------------------- 1 | // rdar: //6857843 2 | #define NONNULL_ATTR __attribute__((nonnull)) 3 | -------------------------------------------------------------------------------- /examples/SemaObjC/nowarn-superclass-method-mismatch.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -Wsuper-class-method-mismatch -verify %s 2 | // expected-no-diagnostics 3 | // rdar://11793793 4 | 5 | @class NSString; 6 | 7 | @interface Super 8 | @property (nonatomic) NSString *thingy; 9 | @property () __weak id PROP; 10 | @end 11 | 12 | @interface Sub : Super 13 | @end 14 | 15 | @implementation Sub 16 | - (void)setThingy:(NSString *)val 17 | { 18 | [super setThingy:val]; 19 | } 20 | @synthesize PROP; 21 | @end 22 | -------------------------------------------------------------------------------- /examples/SemaObjC/ns-consumed-error-not-warning.m: -------------------------------------------------------------------------------- 1 | // RUN: rm -rf %t 2 | // RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs -fobjc-arc -verify -fblocks -triple x86_64-apple-darwin10.0.0 -DOBJCARC %s 3 | // rdar://36265651 4 | 5 | @interface A 6 | -(void) m:(id)p; // expected-note {{parameter declared here}} 7 | @end 8 | 9 | @interface B : A 10 | -(void) m:(__attribute__((ns_consumed)) id)p; // expected-error {{overriding method has mismatched ns_consumed attribute on its parameter}} 11 | @end 12 | 13 | @import empty; 14 | -------------------------------------------------------------------------------- /examples/SemaObjC/ns_returns_retained_block_return.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wno-objc-root-class %s 2 | // RUN: %clang_cc1 -x objective-c++ -fblocks -fsyntax-only -verify -Wno-objc-root-class %s 3 | // RUN: %clang_cc1 -fblocks -fobjc-arc -fsyntax-only -verify -Wno-objc-root-class %s 4 | // RUN: %clang_cc1 -x objective-c++ -fblocks -fobjc-arc -fsyntax-only -verify -Wno-objc-root-class %s 5 | // expected-no-diagnostics 6 | // rdar://17259812 7 | 8 | typedef void (^BT) (); 9 | 10 | BT foo() __attribute__((ns_returns_retained)); 11 | 12 | @interface I 13 | BT foo() __attribute__((ns_returns_retained)); 14 | - (BT) Meth __attribute__((ns_returns_retained)); 15 | + (BT) ClsMeth __attribute__((ns_returns_retained)); 16 | @end 17 | 18 | @implementation I 19 | BT foo() __attribute__((ns_returns_retained)) {return ^{}; } 20 | - (BT) Meth {return ^{}; } 21 | + (BT) ClsMeth {return ^{}; } 22 | @end 23 | -------------------------------------------------------------------------------- /examples/SemaObjC/nsobject-attribute-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | 4 | @interface NSObject 5 | - (id)self; 6 | - (id)copy; 7 | @end 8 | 9 | typedef struct _foo *__attribute__((NSObject)) Foo_ref; 10 | 11 | @interface TestObject { 12 | Foo_ref dict; 13 | } 14 | @property(retain) Foo_ref dict; 15 | @end 16 | 17 | @implementation TestObject 18 | @synthesize dict; 19 | @end 20 | 21 | @interface NSDictionary 22 | - (int)retainCount; 23 | @end 24 | 25 | int main(int argc, char *argv[]) { 26 | NSDictionary *dictRef; 27 | Foo_ref foo = (Foo_ref)dictRef; 28 | 29 | // do Properties retain? 30 | int before = [dictRef retainCount]; 31 | int after = [dictRef retainCount]; 32 | 33 | if ([foo retainCount] != [dictRef retainCount]) { 34 | } 35 | 36 | // do Blocks retain? 37 | { 38 | void (^block)(void) = ^{ 39 | [foo self]; 40 | }; 41 | before = [foo retainCount]; 42 | id save = [block copy]; 43 | after = [foo retainCount]; 44 | if (after <= before) { 45 | ; 46 | } 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /examples/SemaObjC/nullability-arc.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fobjc-arc -fsyntax-only -Woverriding-method-mismatch %s -verify 2 | 3 | __attribute__((objc_root_class)) 4 | @interface NSFoo 5 | @end 6 | 7 | // ARC qualifiers stacked with nullability. 8 | void accepts_arc_qualified(NSFoo * __unsafe_unretained _Nonnull obj) { 9 | accepts_arc_qualified(0); // expected-warning{{null passed to a callee that requires a non-null argument}} 10 | } 11 | -------------------------------------------------------------------------------- /examples/SemaObjC/nullability_macro.m: -------------------------------------------------------------------------------- 1 | // Test that nullability attributes still get merged even though they are 2 | // wrapped with a MacroQualifiedType. This should just compile with no errors. 3 | // RUN: %clang_cc1 %s -Wno-objc-root-class -fsyntax-only -verify 4 | // expected-no-diagnostics 5 | #define UI_APPEARANCE_SELECTOR __attribute__((annotate("ui_appearance_selector"))) 6 | 7 | @class UIColor; 8 | 9 | @interface Test 10 | @property(null_resettable, nonatomic, strong) UIColor *onTintColor UI_APPEARANCE_SELECTOR; 11 | @end 12 | 13 | @implementation Test 14 | - (void)setOnTintColor:(nullable UIColor *)onTintColor { 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /examples/SemaObjC/nullable-weak-property.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fobjc-arc -fobjc-runtime-has-weak -Wnullable-to-nonnull-conversion %s -verify 2 | 3 | 4 | // rdar://19985330 5 | @interface NSObject @end 6 | 7 | @class NSFoo; 8 | void foo (NSFoo * _Nonnull); 9 | 10 | @interface NSBar : NSObject 11 | @property(weak) NSFoo *property1; 12 | @end 13 | 14 | #pragma clang assume_nonnull begin 15 | @interface NSBar () 16 | @property(weak) NSFoo *property2; 17 | @end 18 | 19 | #pragma clang assume_nonnull end 20 | 21 | @implementation NSBar 22 | - (void) Meth { 23 | foo (self.property1); // no warning because nothing is inferred 24 | foo (self.property2); // expected-warning {{implicit conversion from nullable pointer 'NSFoo * _Nullable' to non-nullable pointer type 'NSFoo * _Nonnull'}} 25 | } 26 | @end 27 | -------------------------------------------------------------------------------- /examples/SemaObjC/objc-buffered-methods.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | // rdar://8843851 4 | 5 | int* global; 6 | 7 | @interface I 8 | - (void) Meth; 9 | @property int prop; 10 | @property int prop1; 11 | @end 12 | 13 | @implementation I 14 | + (void) _defaultMinSize { }; 15 | static void _initCommon() { 16 | Class graphicClass; 17 | [graphicClass _defaultMinSize]; 18 | } 19 | 20 | - (void) Meth { [self Forw]; } // No warning now 21 | - (void) Forw {} 22 | - (int) func { return prop; } // compiles - synthesized ivar will be accessible here. 23 | - (int)get_g { return global; } // No warning here - synthesized ivar will be accessible here. 24 | @synthesize prop; 25 | @synthesize prop1=global; 26 | @end 27 | -------------------------------------------------------------------------------- /examples/SemaObjC/objc-container-subscripting-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | typedef unsigned int size_t; 4 | @protocol P @end 5 | 6 | @interface NSMutableArray 7 | @end 8 | 9 | @interface XNSMutableArray 10 | @end 11 | 12 | int main() { 13 | id array; 14 | id oldObject = array[10]; // expected-warning {{instance method '-objectAtIndexedSubscript:' not found (return type defaults to 'id')}} 15 | 16 | array[10] = 0; // expected-warning {{instance method '-setObject:atIndexedSubscript:' not found (return type defaults to 'id')}} 17 | 18 | id

p_array; 19 | oldObject = p_array[10]; // expected-error {{expected method to read array element not found on object of type 'id

'}} 20 | 21 | p_array[10] = 0; // expected-error {{expected method to write array element not found on object of type 'id

'}} 22 | } 23 | -------------------------------------------------------------------------------- /examples/SemaObjC/objc-container-subscripting-attr.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // rdar://16842487 3 | // pr19682 4 | 5 | @interface Subscriptable 6 | - (id)objectForKeyedSubscript:(id)sub __attribute__((unavailable)); // expected-note 2 {{'objectForKeyedSubscript:' has been explicitly marked unavailable here}} 7 | - (void)setObject:(id)object forKeyedSubscript:(id)key __attribute__((unavailable)); // expected-note {{'setObject:forKeyedSubscript:' has been explicitly marked unavailable here}} 8 | @end 9 | 10 | id test(Subscriptable *obj) { 11 | obj[obj] = obj; // expected-error {{'setObject:forKeyedSubscript:' is unavailable}} 12 | return obj[obj]; // expected-error {{'objectForKeyedSubscript:' is unavailable}} 13 | } 14 | 15 | id control(Subscriptable *obj) { 16 | return [obj objectForKeyedSubscript:obj]; // expected-error {{'objectForKeyedSubscript:' is unavailable}} 17 | } 18 | 19 | -------------------------------------------------------------------------------- /examples/SemaObjC/objc-cstyle-args-in-methods.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -Wno-deprecated-declarations -verify -Wno-objc-root-class %s 2 | 3 | @interface Foo 4 | - (id)test:(id)one, id two; 5 | - (id)bad:(id)one, id two, double three; 6 | @end 7 | 8 | @implementation Foo 9 | - (id)test:(id )one, id two {return two; } 10 | - (id)bad:(id)one, id two, double three { return two; } 11 | @end 12 | 13 | 14 | int main() { 15 | Foo *foo; 16 | [foo test:@"One", @"Two"]; 17 | [foo bad:@"One", @"Two"]; // expected-error {{too few arguments to method call}} 18 | [foo bad:@"One", @"Two", 3.14]; 19 | [foo bad:@"One", @"Two", 3.14, @"Two"]; // expected-error {{too many arguments to method call}} 20 | } 21 | -------------------------------------------------------------------------------- /examples/SemaObjC/objc-qualified-property-lookup.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | // rdar://9078584 4 | 5 | @interface NSObject @end 6 | 7 | @protocol TextInput 8 | -editRange; 9 | @end 10 | 11 | @interface I { 12 | NSObject* editor; 13 | } 14 | - (id) Meth; 15 | @end 16 | 17 | @implementation I 18 | - (id) Meth { 19 | return editor.editRange; 20 | } 21 | @end 22 | 23 | -------------------------------------------------------------------------------- /examples/SemaObjC/objc-string-constant.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -Wsemicolon-before-method-body %s -verify -fsyntax-only 2 | 3 | #define nil 0 /* id of Nil instance */ 4 | 5 | @interface NSObject 6 | @end 7 | 8 | @interface NSString : NSObject 9 | 10 | @end 11 | 12 | @interface NSMutableString : NSString 13 | 14 | @end 15 | 16 | @interface NSSimpleCString : NSString { 17 | @protected 18 | char *bytes; 19 | int numBytes; 20 | } 21 | @end 22 | 23 | @interface NSConstantString : NSSimpleCString 24 | @end 25 | 26 | 27 | @interface Subclass : NSObject 28 | - (NSString *)token; 29 | @end 30 | 31 | @implementation Subclass 32 | - (NSString *)token; // expected-warning {{semicolon before method body is ignored}} 33 | { 34 | NSMutableString *result = nil; 35 | 36 | return (result != nil) ? result : @""; 37 | } 38 | @end 39 | 40 | -------------------------------------------------------------------------------- /examples/SemaObjC/objc2-warn-weak-decl.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -fobjc-gc -verify %s 2 | // RUN: %clang_cc1 -x objective-c++ -triple i386-apple-darwin9 -fsyntax-only -fobjc-gc -verify %s 3 | struct S { 4 | __weak id p; // expected-warning {{__weak attribute cannot be specified on a field declaration}} 5 | }; 6 | 7 | int main () 8 | { 9 | __weak id local; // expected-warning {{Objective-C GC does not allow weak variables on the stack}} 10 | } 11 | 12 | -------------------------------------------------------------------------------- /examples/SemaObjC/opaque-is-access.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang -target x86_64-apple-darwin -arch arm64 -mios-version-min=7 -fsyntax-only %s -Xclang -verify 2 | // RUN: %clang -target x86_64-apple-darwin -arch x86_64 -mios-simulator-version-min=7 -fsyntax-only %s -Xclang -verify 3 | // rdar://10709102 4 | 5 | typedef struct objc_object { 6 | struct objc_class *isa; 7 | } *id; 8 | 9 | @interface NSObject { 10 | struct objc_class *isa; 11 | } 12 | @end 13 | @interface Whatever : NSObject 14 | +self; 15 | @end 16 | 17 | static void func() { 18 | 19 | id x; 20 | 21 | [(*x).isa self]; // expected-error {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}} 22 | [x->isa self]; // expected-error {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}} 23 | } 24 | -------------------------------------------------------------------------------- /examples/SemaObjC/override-nullability.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fobjc-arc -fobjc-runtime-has-weak -Wnonnull %s -verify 2 | //rdar://19211059 3 | 4 | @interface NSObject @end 5 | 6 | @interface Base : NSObject 7 | - (nonnull id)bad:(nullable id)obj; // expected-note 2 {{previous declaration is here}} 8 | - (nullable id)notAsBad:(nonnull id)obj; 9 | @end 10 | 11 | @interface Sub : Base 12 | - (nullable id)bad:(nonnull id)obj; // expected-warning {{conflicting nullability specifier on return types, 'nullable' conflicts with existing specifier 'nonnull'}} \ 13 | // expected-warning {{conflicting nullability specifier on parameter types, 'nonnull' conflicts with existing specifier 'nullable'}} 14 | - (nonnull id)notAsBad:(nullable id)obj; 15 | @end 16 | -------------------------------------------------------------------------------- /examples/SemaObjC/overriding-property-in-class-extension.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Weverything %s 2 | // expected-no-diagnostics 3 | // rdar://12103434 4 | 5 | @class NSString; 6 | 7 | @interface NSObject @end 8 | 9 | @interface MyClass : NSObject 10 | 11 | @property (nonatomic, copy, readonly) NSString* name; 12 | 13 | @end 14 | 15 | @interface MyClass () { 16 | NSString* _name; 17 | } 18 | 19 | @property (nonatomic, copy) NSString* name; 20 | 21 | @end 22 | 23 | @implementation MyClass 24 | 25 | @synthesize name = _name; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /examples/SemaObjC/pedantic-dynamic-test.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | // rdar: // 7860960 4 | 5 | @interface I 6 | { 7 | int window; 8 | } 9 | @property int window, noWarningNeeded; 10 | @end 11 | 12 | @implementation I 13 | 14 | @synthesize window; 15 | 16 | @dynamic noWarningNeeded; 17 | @end 18 | -------------------------------------------------------------------------------- /examples/SemaObjC/pragma-pack.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | 4 | // Make sure pragma pack works inside ObjC methods. 5 | @interface X 6 | @end 7 | @implementation X 8 | - (void)Y { 9 | #pragma pack(push, 1) 10 | struct x { 11 | char a; 12 | int b; 13 | }; 14 | #pragma pack(pop) 15 | typedef char check_[sizeof (struct x) == 5 ? 1 : -1]; 16 | } 17 | @end 18 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-11.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | @interface NSSound 5 | @end 6 | @interface NSFont 7 | @end 8 | 9 | @interface NSSound (Adds) 10 | @end 11 | 12 | @implementation NSSound (Adds) 13 | - foo { 14 | return self; 15 | } 16 | - (void)setFoo:obj { 17 | } 18 | @end 19 | 20 | @implementation NSFont (Adds) 21 | 22 | - xx { 23 | NSSound *x; 24 | id o; 25 | 26 | // GCC does *not* warn about the following. Since foo/setFoo: are not in the 27 | // class or category interface for NSSound, the compiler shouldn't find them. 28 | // For now, we will support GCC's behavior (sigh). 29 | o = [x foo]; 30 | o = x.foo; 31 | [x setFoo:o]; 32 | x.foo = o; 33 | return 0; 34 | } 35 | 36 | @end 37 | 38 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-4.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify %s 2 | 3 | @interface Object 4 | @end 5 | 6 | @protocol ProtocolObject 7 | @property int class; 8 | @property (copy) id MayCauseError; 9 | @end 10 | 11 | @protocol ProtocolDerivedGCObject 12 | @property int Dclass; 13 | @end 14 | 15 | @interface GCObject : Object { 16 | int ifield; 17 | int iOwnClass; 18 | int iDclass; 19 | } 20 | @property int OwnClass; 21 | @end 22 | 23 | @interface ReleaseObject : GCObject { 24 | int newO; 25 | int oldO; 26 | } 27 | @property (retain) id MayCauseError; // expected-warning {{'copy' attribute on property 'MayCauseError' does not match the property inherited from 'ProtocolObject'}} 28 | @end 29 | 30 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-5.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify %s 2 | 3 | @protocol P1 @end 4 | @protocol P2 @end 5 | @protocol P3 @end 6 | 7 | @interface NSData @end 8 | 9 | @interface MutableNSData : NSData @end 10 | 11 | @interface Base : NSData // expected-note {{receiver is instance of class declared here}} 12 | @property(readonly) id ref; 13 | @property(readonly) Base *p_base; 14 | @property(readonly) NSData *nsdata; 15 | @property(readonly) NSData * m_nsdata; 16 | @end 17 | 18 | @interface Data : Base 19 | @property(readonly) NSData *ref; 20 | @property(readonly) Data *p_base; 21 | @property(readonly) MutableNSData * m_nsdata; 22 | @end 23 | 24 | @interface MutedData: Data 25 | @property(readonly) id p_base; 26 | @end 27 | 28 | @interface ConstData : Data 29 | @property(readonly) ConstData *p_base; 30 | @end 31 | 32 | void foo(Base *b, id x) { 33 | [ b setRef: x ]; // expected-warning {{method '-setRef:' not found}} 34 | } 35 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-7.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | typedef signed char BOOL; 4 | typedef struct _NSZone NSZone; 5 | 6 | @protocol NSObject 7 | - (BOOL)isEqual:(id)object; 8 | @end 9 | 10 | @protocol NSCopying 11 | - (id)copyWithZone:(NSZone *)zone; 12 | @end 13 | 14 | @interface NSObject {} 15 | @end 16 | 17 | @class NSString, NSData, NSMutableData, NSMutableDictionary, NSMutableArray; 18 | 19 | @interface SCMObject : NSObject {} 20 | @property(assign) SCMObject *__attribute__((objc_gc(weak))) parent; 21 | @end 22 | 23 | @interface SCMNode : SCMObject 24 | { 25 | NSString *_name; 26 | } 27 | @property(copy) NSString *name; 28 | @end 29 | 30 | @implementation SCMNode 31 | @synthesize name = _name; 32 | - (void) setParent:(SCMObject *__attribute__((objc_gc(weak)))) inParent { 33 | super.parent = inParent; 34 | } 35 | @end 36 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-and-class-extension.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | /** 4 | When processing @synthesize, treat ivars in a class extension the same as ivars in the class @interface, 5 | and treat ivars in a superclass extension the same as ivars in the superclass @interface. 6 | In particular, when searching for an ivar to back an @synthesize, do look at ivars in the class's own class 7 | extension but ignore any ivars in superclass class extensions. 8 | */ 9 | 10 | @interface Super { 11 | int ISA; 12 | } 13 | @end 14 | 15 | @interface Super() { 16 | int Property; // expected-note {{previously declared 'Property' here}} 17 | } 18 | @end 19 | 20 | @interface SomeClass : Super { 21 | int interfaceIvar1; 22 | int interfaceIvar2; 23 | } 24 | @property int Property; 25 | @property int Property1; 26 | @end 27 | 28 | @interface SomeClass () { 29 | int Property1; 30 | } 31 | @end 32 | 33 | @implementation SomeClass 34 | @synthesize Property; // expected-error {{property 'Property' attempting to use instance variable 'Property' declared in super class 'Super'}} 35 | @synthesize Property1; // OK 36 | @end 37 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-and-ivar-use.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | // Do not issue error if 'ivar' used previously belongs to the inherited class 4 | // and has same name as @dynalic property in current class. 5 | 6 | typedef signed char BOOL; 7 | 8 | @protocol IDEBuildable 9 | @property (readonly) BOOL hasRecursiveDependencyCycle; 10 | @end 11 | 12 | @protocol IDEBuildableProduct 13 | @end 14 | 15 | @interface IDEBuildableSupportMixIn 16 | @property (readonly) BOOL hasRecursiveDependencyCycle; 17 | @end 18 | 19 | @interface Xcode3TargetBuildable 20 | { 21 | IDEBuildableSupportMixIn *_buildableMixIn; 22 | } 23 | @end 24 | 25 | @interface Xcode3TargetProduct : Xcode3TargetBuildable 26 | @end 27 | 28 | @implementation Xcode3TargetBuildable 29 | - (BOOL)hasRecursiveDependencyCycle 30 | { 31 | return [_buildableMixIn hasRecursiveDependencyCycle]; 32 | } 33 | @end 34 | 35 | @implementation Xcode3TargetProduct 36 | @dynamic hasRecursiveDependencyCycle; 37 | @end 38 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-assign-on-object-type.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wobjc-property-assign-on-object-type %s 2 | 3 | @interface Foo @end 4 | @protocol Prot @end 5 | 6 | @interface Bar 7 | @property(assign, readonly) Foo* o1; // expected-warning {{'assign' property of object type may become a dangling reference; consider using 'unsafe_unretained'}} 8 | @property(unsafe_unretained, readonly) Foo* o2; 9 | 10 | @property(assign) Class classProperty; 11 | @property(assign) Class classWithProtocolProperty; 12 | @property(assign) int s1; 13 | @property(assign) int* s2; 14 | @end 15 | 16 | @interface Bar () 17 | @property(readwrite) Foo* o1; 18 | @property(readwrite) Foo* o2; 19 | @end 20 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-category-2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // Test that a property can be synthesize in a category 3 | // implementation with no error. 4 | 5 | @protocol MyProtocol 6 | @property float myFloat; 7 | @property float anotherFloat; // expected-note 2 {{property declared}} 8 | @end 9 | 10 | @interface MyObject { float anotherFloat; } 11 | @end 12 | 13 | @interface MyObject (CAT) 14 | @end 15 | 16 | @implementation MyObject (CAT) // expected-warning {{property 'anotherFloat' requires method}} \ 17 | // expected-warning {{property 'anotherFloat' requires method 'setAnotherFloat:'}} 18 | @dynamic myFloat; // OK 19 | @synthesize anotherFloat; // expected-error {{@synthesize not allowed in a category's implementation}} 20 | @end 21 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-category-3.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | @protocol P 4 | @property(readonly) int X; // expected-note {{property declared here}} 5 | @end 6 | 7 | @protocol P1

8 | @property (copy) id ID; 9 | @end 10 | 11 | @interface I 12 | @end 13 | 14 | @interface I (Cat)

15 | @property float X; // expected-warning {{property type 'float' is incompatible with type 'int' inherited from 'P'}} 16 | @end 17 | 18 | @interface I (Cat2) 19 | @property (retain) id ID; // expected-warning {{'copy' attribute on property 'ID' does not match the property inherited from 'P1'}} 20 | @end 21 | 22 | 23 | @interface A 24 | @property(assign) int categoryProperty; 25 | @end 26 | 27 | // Don't issue warning on unimplemented setter/getter 28 | // because property is @dynamic. 29 | @implementation A 30 | @dynamic categoryProperty; 31 | @end 32 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-choose-expr.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | 4 | @interface NSArray 5 | -(int)count; 6 | @end 7 | 8 | // 9 | char* f(NSArray *array) { 10 | return _Generic(__builtin_choose_expr(__builtin_types_compatible_p(__typeof__(array.count), void), 0.f, array.count), 11 | unsigned int:"uint", 12 | float:"void", 13 | default: "ignored"); 14 | } 15 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-dot-receiver.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s 3 | // expected-no-diagnostics 4 | // rdar://8962253 5 | 6 | @interface Singleton { 7 | } 8 | + (Singleton*) instance; 9 | @end 10 | 11 | @implementation Singleton 12 | 13 | - (void) someSelector { } 14 | 15 | + (Singleton*) instance { return 0; } 16 | 17 | + (void) compileError 18 | { 19 | [Singleton.instance someSelector]; // clang issues error here 20 | } 21 | 22 | @end 23 | 24 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-error-readonly-assign.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @interface A 4 | -(int) x; 5 | @property (readonly) int x; 6 | @property int ok; 7 | @end 8 | 9 | @interface B 10 | -(void) setOk:(int)arg; 11 | -(int) x; 12 | -(int) ok; 13 | @end 14 | 15 | void f0(A *a, B* b) { 16 | a.x = 10; // expected-error {{assignment to readonly property}} 17 | a.ok = 20; 18 | b.x = 10; // expected-error {{no setter method 'setX:' for assignment to property}} 19 | b.ok = 20; 20 | } 21 | 22 | typedef struct { 23 | int i1, i2; 24 | } NSRect; 25 | 26 | NSRect NSMakeRect(); 27 | 28 | @interface NSWindow 29 | { 30 | NSRect _frame; 31 | } 32 | - (NSRect)frame; 33 | @end 34 | 35 | @interface NSWindow (Category) 36 | -(void)methodToMakeClangCrash; 37 | @end 38 | 39 | @implementation NSWindow (Category) 40 | -(void)methodToMakeClangCrash 41 | { 42 | self.frame = NSMakeRect(); // expected-error {{no setter method 'setFrame:' for assignment to property}} 43 | } 44 | @end 45 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-expression-error.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | @interface AddressMyProperties 4 | { 5 | unsigned index; 6 | } 7 | @property unsigned index; 8 | @end 9 | 10 | @implementation AddressMyProperties 11 | @synthesize index; 12 | @end 13 | 14 | int main() { 15 | AddressMyProperties *object; 16 | &object.index; // expected-error {{address of property expression requested}} 17 | return 0; 18 | } 19 | 20 | typedef int Foo; 21 | void test() { 22 | Foo.x; // expected-error {{expected identifier or '('}} 23 | } 24 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-implement-readonly-with-custom-setter.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // rdar://34192541 3 | 4 | @class NSString; 5 | 6 | @protocol MyProtocol 7 | @property (nonatomic, strong, readonly) NSString *myString; 8 | @end 9 | 10 | @interface MyClass 11 | // Don't warn about this setter: 12 | @property (nonatomic, strong, setter=setMYString:) NSString *myString; 13 | 14 | 15 | @property (nonatomic, strong, readonly) NSString *overridenInClass; // expected-note {{property declared here}} 16 | @end 17 | 18 | @interface MySubClass: MyClass 19 | @property (nonatomic, strong, setter=setMYOverride:) NSString *overridenInClass; 20 | // expected-warning@-1 {{'setter' attribute on property 'overridenInClass' does not match the property inherited from 'MyClass'}} 21 | @end 22 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-in-class-extension.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // rdar://7766184 3 | 4 | @interface Foo @end 5 | 6 | @interface Foo () 7 | @property (readonly) int bar; 8 | @end 9 | 10 | void FUNC () { 11 | Foo *foo; 12 | foo.bar = 0; // expected-error {{assignment to readonly property}} 13 | } 14 | 15 | // rdar://8747333 16 | @class NSObject; 17 | 18 | @interface rdar8747333 { 19 | @private 20 | NSObject *_bar; 21 | NSObject *_baz; 22 | NSObject *_bam; 23 | } 24 | - (NSObject *)baz; 25 | @end 26 | 27 | @interface rdar8747333 () 28 | - (NSObject *)bar; 29 | @end 30 | 31 | @interface rdar8747333 () 32 | @property (readwrite, assign) NSObject *bar; 33 | @property (readwrite, assign) NSObject *baz; 34 | @property (readwrite, assign) NSObject *bam; 35 | @property (readwrite, assign) NSObject *warn; 36 | @end 37 | 38 | @interface rdar8747333 () 39 | - (NSObject *)bam; 40 | - (NSObject *)warn; 41 | - (void)setWarn : (NSObject *)val; 42 | @end 43 | 44 | @implementation rdar8747333 45 | @synthesize bar = _bar; 46 | @synthesize baz = _baz; 47 | @synthesize bam = _bam; 48 | @dynamic warn; 49 | @end 50 | 51 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-ivar-mismatch.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // Test that arithmetic types on property and its ivar have exact match. 3 | 4 | @interface Test4 5 | { 6 | char ivar; // expected-note{{instance variable is declared here}} 7 | } 8 | @property int prop; 9 | @end 10 | 11 | @implementation Test4 12 | @synthesize prop = ivar; // expected-error {{type of property 'prop' ('int') does not match type of instance variable 'ivar' ('char')}} 13 | @end 14 | 15 | 16 | @interface Test5 17 | { 18 | void * _P; // expected-note {{instance variable is declared here}} 19 | } 20 | @property int P; 21 | @end 22 | 23 | @implementation Test5 24 | @synthesize P=_P; // expected-error {{ype of property 'P' ('int') does not match type of instance variable '_P' ('void *')}} 25 | @end 26 | 27 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-lookup-in-id.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // rdar://9106929 3 | 4 | typedef struct objc_class *Class; 5 | 6 | typedef struct objc_object { 7 | Class isa; 8 | } *id; 9 | 10 | 11 | typedef struct __FSEventStream* FSEventStreamRef; 12 | 13 | extern id NSApp; 14 | 15 | @interface FileSystemMonitor { 16 | 17 | FSEventStreamRef fsEventStream; 18 | } 19 | @property(assign) FSEventStreamRef fsEventStream; 20 | 21 | @end 22 | 23 | @implementation FileSystemMonitor 24 | @synthesize fsEventStream; 25 | 26 | - (void)startFSEventGathering:(id)sender 27 | { 28 | fsEventStream = [NSApp delegate].fsEventStream; // expected-warning {{instance method '-delegate' not found (return type defaults to 'id')}} \ 29 | // expected-error {{property 'fsEventStream' not found on object of type 'id'}} 30 | 31 | } 32 | @end 33 | 34 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-method-lookup-impl.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | 4 | @interface SSyncCEList 5 | { 6 | id _list; 7 | } 8 | @end 9 | 10 | @implementation SSyncCEList 11 | 12 | - (id) list { return 0; } 13 | @end 14 | 15 | @interface SSyncConflictList : SSyncCEList 16 | @end 17 | 18 | @implementation SSyncConflictList 19 | 20 | - (id)Meth : (SSyncConflictList*)other 21 | { 22 | return other.list; 23 | } 24 | @end 25 | 26 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-missing.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | // PR3234 4 | 5 | @protocol NSCopying @end 6 | @interface NSObject @end 7 | 8 | void f1(NSObject *o) 9 | { 10 | o.foo; // expected-error{{property 'foo' not found on object of type 'NSObject *'}} 11 | } 12 | 13 | void f2(id o) 14 | { 15 | o.foo; // expected-error{{property 'foo' not found on object of type 'id'}} 16 | } 17 | 18 | void f3(id o) 19 | { 20 | o.foo; // expected-error{{property 'foo' not found on object of type 'id'}} 21 | } 22 | 23 | // rdar://8851803 24 | @class SomeOtherClass; // expected-note {{forward declaration of class here}} 25 | 26 | @interface MyClass { 27 | SomeOtherClass *someOtherObject; 28 | } 29 | @end 30 | 31 | void foo(MyClass *myObject) { 32 | myObject.someOtherObject.someProperty = 0; // expected-error {{property 'someOtherObject' refers to an incomplete Objective-C class 'SomeOtherClass' (with no @interface available)}} 33 | } 34 | 35 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-nonfragile-abi.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | typedef signed char BOOL; 5 | 6 | @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; 7 | 8 | @protocol NSObject 9 | - (BOOL)isEqual:(id)object; 10 | @end 11 | 12 | @interface NSObject {} 13 | @end 14 | 15 | @interface XCDeviceWillExecuteInfoBaton : NSObject {} 16 | @property (retain) __attribute__((objc_gc(strong))) NSString *sdkPath; 17 | @end 18 | 19 | @implementation XCDeviceWillExecuteInfoBaton 20 | @synthesize sdkPath; 21 | @end 22 | 23 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-noprotocol-warning.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | 5 | @interface Object 6 | + (id) new; 7 | @end 8 | 9 | @protocol GCObject 10 | @property int class; 11 | @end 12 | 13 | @protocol DerivedGCObject 14 | @property int Dclass; 15 | @end 16 | 17 | @interface GCObject : Object { 18 | int ifield; 19 | int iOwnClass; 20 | int iDclass; 21 | } 22 | @property int OwnClass; 23 | @end 24 | 25 | @implementation GCObject : Object 26 | @synthesize class=ifield; 27 | @synthesize Dclass=iDclass; 28 | @synthesize OwnClass=iOwnClass; 29 | @end 30 | 31 | int main(int argc, char **argv) { 32 | GCObject *f = [GCObject new]; 33 | f.class = 5; 34 | f.Dclass = 1; 35 | f.OwnClass = 3; 36 | return f.class + f.Dclass + f.OwnClass - 9; 37 | } 38 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-not-lvalue.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | typedef struct NSSize { 4 | int width; 5 | struct { 6 | int dim; 7 | } inner; 8 | } NSSize; 9 | 10 | @interface Foo { 11 | NSSize _size; 12 | } 13 | @property NSSize size; 14 | @end 15 | 16 | void foo() { 17 | Foo *f; 18 | f.size.width = 2.2; // expected-error {{expression is not assignable}} 19 | f.size.inner.dim = 200; // expected-error {{expression is not assignable}} 20 | } 21 | 22 | // radar 7628953 23 | 24 | @interface Gorf { 25 | } 26 | - (NSSize)size; 27 | @end 28 | 29 | @implementation Gorf 30 | - (void)MyView_sharedInit { 31 | self.size.width = 2.2; // expected-error {{expression is not assignable}} 32 | } 33 | - (NSSize)size {} 34 | @end 35 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-ns-returns-not-retained-attr.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // rdar://9636091 3 | 4 | @interface I 5 | @property (nonatomic, retain) id newName __attribute__((ns_returns_not_retained)) ; 6 | 7 | @property (nonatomic, retain) id newName1 __attribute__((ns_returns_not_retained)) ; 8 | - (id) newName1 __attribute__((ns_returns_not_retained)); 9 | 10 | @property (nonatomic, retain) id newName2 __attribute__((ns_returns_not_retained)); // expected-note {{roperty declared here}} 11 | - (id) newName2; // expected-warning {{property declared as returning non-retained objects; getter returning retained objects}} 12 | @end 13 | 14 | @implementation I 15 | @synthesize newName; 16 | 17 | @synthesize newName1; 18 | - (id) newName1 { return 0; } 19 | 20 | @synthesize newName2; 21 | @end 22 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-ownership-attr.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // rdar://15014468 3 | 4 | @protocol P 5 | @property(readonly) id z; 6 | @end 7 | 8 | @interface Foo 9 | @property (readonly) id x; 10 | @end 11 | 12 | @interface MutableFoo : Foo 13 | @property (copy) id x; 14 | @end 15 | 16 | @interface Foo (Cat)

17 | @property (copy) id z; // expected-warning {{'copy' attribute on property 'z' does not match the property inherited from 'P'}} 18 | @end 19 | 20 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-redundant-decl-accessor.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -Werror -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | 4 | @interface MyClass { 5 | const char *_myName; 6 | } 7 | 8 | @property const char *myName; 9 | 10 | - (const char *)myName; 11 | - (void)setMyName:(const char *)name; 12 | 13 | @end 14 | 15 | @implementation MyClass 16 | 17 | @synthesize myName = _myName; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /examples/SemaObjC/property-weak.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | @interface foo 5 | @property(nonatomic) int foo __attribute__((weak_import)); 6 | @end 7 | -------------------------------------------------------------------------------- /examples/SemaObjC/protocol-expr-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | @protocol fproto @end 5 | 6 | @protocol p1 7 | @end 8 | 9 | @class cl; 10 | 11 | int main() 12 | { 13 | Protocol *proto = @protocol(p1); 14 | Protocol *fproto = @protocol(fproto); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /examples/SemaObjC/protocol-id-test-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -Wno-objc-root-class %s 2 | 3 | @interface FF 4 | - (void) Meth; 5 | @end 6 | 7 | @protocol P 8 | @end 9 | 10 | @interface INTF

// expected-note {{receiver is instance of class declared here}} 11 | - (void)IMeth; 12 | @end 13 | 14 | @implementation INTF 15 | - (void)IMeth {INTF

*pi; [pi Meth]; } // expected-warning {{instance method '-Meth' not found (return type defaults to 'id'); did you mean '-IMeth'?}} 16 | @end 17 | -------------------------------------------------------------------------------- /examples/SemaObjC/protocol-id-test-2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -Wno-objc-root-class %s 2 | 3 | @protocol P 4 | @end 5 | 6 | @interface INTF

7 | - (void)IMeth; 8 | @end 9 | 10 | @implementation INTF 11 | - (void)IMeth { [(id

)self Meth]; } // expected-warning {{instance method '-Meth' not found (return type defaults to 'id'); did you mean '-IMeth'?}} 12 | @end 13 | -------------------------------------------------------------------------------- /examples/SemaObjC/protocol-implementation-inherited.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | @protocol P0 5 | -bar; 6 | @end 7 | 8 | @interface A 9 | @end 10 | 11 | // Interface conforms to inherited protocol 12 | 13 | @interface B0 : A 14 | @end 15 | 16 | @implementation B0 17 | @end 18 | 19 | // Interface conforms to a protocol which extends another. The other 20 | // protocol is inherited, and extended methods are implemented. 21 | 22 | @protocol P1 23 | -foo; 24 | @end 25 | 26 | @interface B1 : A 27 | @end 28 | 29 | @implementation B1 30 | -foo { return 0; }; 31 | @end 32 | 33 | // Interface conforms to a protocol whose methods are provided by an 34 | // alternate inherited protocol. 35 | 36 | @protocol P2 37 | -bar; 38 | @end 39 | 40 | @interface B2 : A 41 | @end 42 | 43 | @implementation B2 44 | @end 45 | 46 | // Interface conforms to a protocol whose methods are provided by a base class. 47 | 48 | @interface A1 49 | -bar; 50 | @end 51 | 52 | @interface B3 : A1 53 | @end 54 | 55 | @implementation B3 56 | @end 57 | 58 | -------------------------------------------------------------------------------- /examples/SemaObjC/protocol-lookup-2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | @interface NSObject @end 4 | 5 | @protocol ProtocolA 6 | 7 | + (id)classMethod; 8 | - (id)instanceMethod; 9 | 10 | @end 11 | 12 | @protocol ProtocolB 13 | 14 | @end 15 | 16 | @interface Foo : NSObject 17 | 18 | @end 19 | 20 | @interface SubFoo : Foo 21 | 22 | @end 23 | 24 | @implementation SubFoo 25 | 26 | + (id)method { 27 | return [super classMethod]; 28 | } 29 | 30 | - (id)method { 31 | return [super instanceMethod]; 32 | } 33 | 34 | @end 35 | 36 | 37 | @protocol ProtC 38 | -document; 39 | @end 40 | 41 | @interface I1 : NSObject 42 | @end 43 | 44 | @interface I1(cat) 45 | -document; 46 | @end 47 | 48 | @interface I2 : NSObject 49 | -document; 50 | @end 51 | 52 | @interface I2() 53 | @end 54 | 55 | @implementation I2 56 | - document { return 0; } 57 | @end 58 | -------------------------------------------------------------------------------- /examples/SemaObjC/protocol-lookup.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | @protocol NSObject 4 | - retain; 5 | - release; 6 | @end 7 | 8 | @interface NSObject 9 | - init; 10 | - dealloc; 11 | @end 12 | 13 | @protocol Foo 14 | @end 15 | 16 | @protocol Bar 17 | @end 18 | 19 | @interface Baz : NSObject { 20 | id _foo; 21 | id _bar; 22 | } 23 | - (id)initWithFoo:(id )foo bar:(id )bar; 24 | @end 25 | 26 | @implementation Baz 27 | 28 | - (id)init 29 | { 30 | return [self initWithFoo:0 bar:0]; 31 | } 32 | 33 | - (id)initWithFoo:(id )foo bar:(id )bar 34 | { 35 | self = [super init]; 36 | if (self != 0) { 37 | _foo = [foo retain]; 38 | _bar = [bar retain]; 39 | } 40 | return self; 41 | } 42 | 43 | - dealloc 44 | { 45 | [_foo release]; 46 | [_bar release]; 47 | [super dealloc]; 48 | return 0; 49 | } 50 | 51 | @end 52 | 53 | -------------------------------------------------------------------------------- /examples/SemaObjC/protocol-qualified-class-unsupported.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | #include 5 | 6 | typedef struct objc_class *Class; 7 | typedef struct objc_object { 8 | Class isa; 9 | } *id; 10 | id objc_getClass(const char *s); 11 | 12 | @interface Object 13 | + self; 14 | @end 15 | 16 | @protocol Func 17 | + (void) class_func0; 18 | - (void) instance_func0; 19 | @end 20 | 21 | @interface Derived: Object 22 | @end 23 | 24 | @interface Derived2: Object 25 | @end 26 | 27 | static void doSomething(Class unsupportedObjectType) { 28 | [unsupportedObjectType class_func0]; 29 | } 30 | 31 | static void doSomethingElse(id pleaseConvertToThisType) { 32 | [pleaseConvertToThisType class_func0]; 33 | } 34 | 35 | int main(int argv, char *argc[]) { 36 | doSomething([Derived self]); 37 | doSomething([Derived2 self]); 38 | doSomethingElse([Derived self]); 39 | doSomethingElse([Derived2 self]); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /examples/SemaObjC/protocol-typecheck.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @interface NSObject @end 4 | @protocol XCElementP @end 5 | @protocol XCElementSpacerP @end 6 | 7 | @protocol PWhatever @end 8 | 9 | @interface XX 10 | 11 | - (void)setFlexElement:(NSObject *)flexer; 12 | - (void)setFlexElement2:(NSObject *)flexer; // expected-note{{passing argument to parameter 'flexer' here}} 13 | 14 | @end 15 | 16 | void func() { 17 | NSObject * flexer; 18 | NSObject * flexer2; 19 | XX *obj; 20 | [obj setFlexElement:flexer]; 21 | // FIXME: GCC provides the following diagnostic (which is much better): 22 | // protocol-typecheck.m:21: warning: class 'NSObject ' does not implement the 'XCElementSpacerP' protocol 23 | [obj setFlexElement2:flexer2]; // expected-warning{{incompatible pointer types sending 'NSObject *' to parameter of type 'NSObject *'}} 24 | } 25 | 26 | -------------------------------------------------------------------------------- /examples/SemaObjC/provisional-ivar-lookup.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | // rdar:// 8565343 4 | @interface Foo { 5 | @private 6 | int _foo; 7 | int _foo2; 8 | } 9 | @property (readwrite, nonatomic) int foo, foo1, foo2, foo3; 10 | @property (readwrite, nonatomic) int PROP; 11 | @end 12 | 13 | @implementation Foo 14 | 15 | @synthesize foo = _foo; 16 | @synthesize foo1; 17 | 18 | - (void)setFoo:(int)value { 19 | _foo = foo; // expected-error {{use of undeclared identifier 'foo'}} 20 | } 21 | 22 | - (void)setFoo1:(int)value { 23 | _foo = foo1; // OK 24 | } 25 | 26 | - (void)setFoo2:(int)value { 27 | _foo = foo2; // expected-error {{use of undeclared identifier 'foo2'}} 28 | } 29 | 30 | - (void)setFoo3:(int)value { 31 | _foo = foo3; // OK 32 | } 33 | 34 | @synthesize foo2 = _foo2; 35 | @synthesize foo3; 36 | 37 | @synthesize PROP=PROP; 38 | - (void)setPROP:(int)value { 39 | PROP = value; // OK 40 | } 41 | 42 | @end 43 | 44 | -------------------------------------------------------------------------------- /examples/SemaObjC/rdar6248119.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only %s -verify -fobjc-exceptions 2 | // expected-no-diagnostics 3 | // Test case for: 4 | // @finally doesn't introduce a new scope 5 | 6 | void f0() { 7 | int i; 8 | @try { 9 | } @finally { 10 | int i = 0; 11 | } 12 | } 13 | 14 | void f1() { 15 | int i; 16 | @try { 17 | int i =0; 18 | } @finally { 19 | } 20 | } 21 | 22 | void f2() { 23 | int i; 24 | @try { 25 | } @catch(id e) { 26 | int i = 0; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/SemaObjC/rdr-6211479-array-property.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // 3 | 4 | typedef int T[2]; 5 | 6 | @interface A 7 | @property(assign) T p2; // expected-error {{property cannot have array or function type 'T' (aka 'int [2]')}} 8 | @end 9 | -------------------------------------------------------------------------------- /examples/SemaObjC/receiver-forward-class.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -Wreceiver-forward-class -verify %s 2 | // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -Wreceiver-forward-class -verify %s 3 | // rdar://10686120 4 | 5 | @class A; // expected-note {{forward declaration of class here}} 6 | 7 | @interface B 8 | -(int) width; // expected-note {{using}} 9 | @end 10 | @interface C 11 | -(float) width; // expected-note {{also found}} 12 | @end 13 | 14 | int f0(A *x) { 15 | return [x width]; // expected-warning {{receiver type 'A' for instance message is a forward declaration}} \ 16 | // expected-warning {{multiple methods named 'width' found}} \ 17 | // expected-note {{receiver is treated with 'id' type for purpose of method lookup}} 18 | } 19 | 20 | -------------------------------------------------------------------------------- /examples/SemaObjC/restrict-id-type.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -std=gnu99 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | void f0(restrict id a0) {} 5 | 6 | void f1(restrict id *a0) {} 7 | 8 | void f2(restrict Class a0) {} 9 | 10 | void f3(restrict Class *a0) {} 11 | -------------------------------------------------------------------------------- /examples/SemaObjC/return.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-noreturn -fobjc-exceptions -Wno-objc-root-class %s 2 | 3 | int test1() { 4 | id a; 5 | @throw a; 6 | } 7 | 8 | // PR5286 9 | void test2(int a) { 10 | while (1) { 11 | if (a) 12 | return; 13 | } 14 | } 15 | 16 | // PR5286 17 | void test3(int a) { // expected-warning {{function 'test3' could be declared with attribute 'noreturn'}} 18 | while (1) { 19 | if (a) 20 | @throw (id)0; 21 | } 22 | } 23 | 24 | // - This code always returns, we should not 25 | // issue a noreturn warning. 26 | @class NSException; 27 | @class NSString; 28 | NSString *rdar_4289832() { // no-warning 29 | @try 30 | { 31 | return @"a"; 32 | } 33 | @catch(NSException *exception) 34 | { 35 | return @"b"; 36 | } 37 | @finally 38 | { 39 | } 40 | } 41 | 42 | void exit(int) __attribute__((noreturn)); 43 | @interface rdar10098695 44 | @end 45 | 46 | @implementation rdar10098695 47 | - (void)method { // expected-warning{{method 'method' could be declared with attribute 'noreturn'}} 48 | exit(1); 49 | } 50 | @end 51 | -------------------------------------------------------------------------------- /examples/SemaObjC/selector-2.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -Wselector -verify %s 2 | // expected-no-diagnostics 3 | // rdar://8851684 4 | @interface I 5 | - length; 6 | @end 7 | 8 | static inline SEL IsEmpty() { 9 | return @selector(length); 10 | } 11 | 12 | int main (int argc, const char * argv[]) { 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /examples/SemaObjC/selector-4.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -Wselector -x objective-c %s -include %s -verify 2 | // expected-no-diagnostics 3 | // rdar://16600230 4 | 5 | #ifndef INCLUDED 6 | #define INCLUDED 7 | 8 | #pragma clang system_header 9 | 10 | @interface NSObject @end 11 | @interface NSString @end 12 | 13 | @interface NSString (NSStringExtensionMethods) 14 | - (void)compare:(NSString *)string; 15 | @end 16 | 17 | @interface MyObject : NSObject 18 | @end 19 | 20 | #else 21 | int main() { 22 | (void)@selector(compare:); 23 | } 24 | 25 | @implementation MyObject 26 | 27 | @end 28 | #endif 29 | -------------------------------------------------------------------------------- /examples/SemaObjC/selector-error.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | @interface Foo 4 | - (char*) foo; 5 | - (void) bar; 6 | @end 7 | 8 | @implementation Foo 9 | - (void) bar 10 | { 11 | } 12 | 13 | - (char*) foo 14 | { 15 | char* a,b,c; 16 | a = (char*)@selector(bar); // expected-error {{cannot type cast @selector expression}} 17 | return (char*)@selector(bar); // expected-error {{cannot type cast @selector expression}} 18 | } 19 | @end 20 | 21 | -------------------------------------------------------------------------------- /examples/SemaObjC/selector-overload.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -fsyntax-only 2 | // FIXME: This test needs needs to be run with -verify 3 | 4 | @interface NSObject 5 | + alloc; 6 | - init; 7 | @end 8 | 9 | struct D { 10 | double d; 11 | }; 12 | 13 | @interface Foo : NSObject 14 | 15 | - method:(int)a; 16 | - method:(int)a; 17 | 18 | @end 19 | 20 | @interface Bar : NSObject 21 | 22 | - method:(void *)a; 23 | 24 | @end 25 | 26 | @interface Car : NSObject 27 | 28 | - method:(struct D)a; 29 | 30 | @end 31 | 32 | @interface Zar : NSObject 33 | 34 | - method:(float)a; 35 | 36 | @end 37 | 38 | @interface Rar : NSObject 39 | 40 | - method:(float)a; 41 | 42 | @end 43 | 44 | int main() { 45 | id xx = [[Car alloc] init]; // expected-warning {{incompatible types assigning 'int' to 'id'}} 46 | 47 | [xx method:4]; 48 | } 49 | -------------------------------------------------------------------------------- /examples/SemaObjC/self-assign.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | @interface A 3 | @end 4 | 5 | @implementation A 6 | - (id):(int)x :(int)y { 7 | int z; 8 | // 9 | if (self = [self :x :y]) {} // expected-warning{{using the result of an assignment as a condition without parentheses}} \ 10 | // expected-note{{use '==' to turn this assignment into an equality comparison}} \ 11 | // expected-note{{place parentheses around the assignment to silence this warning}} 12 | return self; 13 | } 14 | @end 15 | -------------------------------------------------------------------------------- /examples/SemaObjC/self-comparison.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | @interface A { 4 | id xxx; 5 | } 6 | -(int)bar; 7 | @end 8 | @implementation A 9 | -(int)bar { 10 | return xxx == xxx; // expected-warning {{self-comparison always evaluates to true}} 11 | } 12 | @end 13 | -------------------------------------------------------------------------------- /examples/SemaObjC/self-declared-in-block.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10 -fblocks -verify -Wno-objc-root-class %s 2 | // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -triple x86_64-apple-darwin10 -fblocks -verify -Wno-objc-root-class %s 3 | // expected-no-diagnostics 4 | // rdar://9154582 5 | 6 | @interface Blocky @end 7 | 8 | @implementation Blocky { 9 | int _a; 10 | } 11 | - (int)doAThing { 12 | ^{ 13 | char self; 14 | return _a; 15 | }(); 16 | return _a; 17 | } 18 | 19 | @end 20 | 21 | 22 | // rdar://9284603 23 | @interface ShadowSelf 24 | { 25 | int _anIvar; 26 | } 27 | @end 28 | 29 | @interface C { 30 | int _cIvar; 31 | } 32 | @end 33 | 34 | @implementation ShadowSelf 35 | - (void)doSomething { 36 | __typeof(self) newSelf = self; 37 | { 38 | __typeof(self) self = newSelf; 39 | (void)_anIvar; 40 | } 41 | { 42 | C* self; 43 | (void) _anIvar; 44 | } 45 | } 46 | - (void)doAThing { 47 | ^{ 48 | id self; 49 | (void)_anIvar; 50 | }(); 51 | } 52 | @end 53 | 54 | -------------------------------------------------------------------------------- /examples/SemaObjC/self-in-function.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s 2 | // expected-no-diagnostics 3 | // rdar://9181463 4 | 5 | typedef struct objc_class *Class; 6 | 7 | typedef struct objc_object { 8 | Class isa; 9 | } *id; 10 | 11 | @interface NSObject 12 | + (id) alloc; 13 | @end 14 | 15 | 16 | void foo(Class self) { 17 | [self alloc]; 18 | (^() { 19 | [self alloc]; 20 | })(); 21 | } 22 | 23 | void bar(Class self) { 24 | Class y = self; 25 | [y alloc]; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /examples/SemaObjC/setter-dotsyntax.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | // rdar://8528170 4 | 5 | @interface NSObject @end 6 | 7 | @protocol MyProtocol 8 | - (int) level; 9 | - (void) setLevel:(int)inLevel; 10 | @end 11 | 12 | @interface MyClass : NSObject 13 | @end 14 | 15 | int main () 16 | { 17 | id c; 18 | c.level = 10; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /examples/SemaObjC/severe-syntax-error.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // rdar://10633434 3 | 4 | @interface testClass 5 | @end 6 | 7 | @class NSArray; 8 | 9 | @implementation testClass 10 | 11 | static NSArray* prefixArray[] = @"BEGIN:", @"END:", @"VERSION:", @"N:", @"FN:", @"TEL;", @"TEL:", nil; // expected-error {{array initializer must be an initializer list}} \ 12 | // expected-error {{expected identifier or '('}} \ 13 | // expected-error {{expected ';' after top level declarator}} 14 | 15 | static NSString* prefixArray1[] = @"BEGIN:", @"END:", @"VERSION:", @"N:", @"FN:", @"TEL;", @"TEL:", nil; // expected-error {{unknown type name 'NSString'}} \ 16 | // expected-error {{expected identifier or '('}} \ 17 | // expected-error {{expected ';' after top level declarator}} 18 | 19 | static char* cArray[] = "BEGIN:", "END"; // expected-error {{array initializer must be an initializer list}} \ 20 | // expected-error {{expected identifier or '('}} \ 21 | // expected-error {{expected ';' after top level declarator}} 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /examples/SemaObjC/stand-alone-implementation.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // radar 7547942 3 | // Allow injection of ivars into implementation's implicit class. 4 | 5 | @implementation INTFSTANDALONE // expected-warning {{cannot find interface declaration for 'INTFSTANDALONE'}} 6 | { 7 | id IVAR1; 8 | id IVAR2; 9 | } 10 | - (id) Meth { return IVAR1; } 11 | @end 12 | 13 | -------------------------------------------------------------------------------- /examples/SemaObjC/static-ivar-ref-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple i386-unknown-unknown -ast-print %s 2>&1 | FileCheck %s 2 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -ast-print %s 2>&1 | FileCheck %s 3 | 4 | @interface current 5 | { 6 | @public 7 | int ivar; 8 | int ivar1; 9 | int ivar2; 10 | } 11 | @end 12 | 13 | current *pc; 14 | 15 | int foo() 16 | { 17 | return pc->ivar2 + (*pc).ivar + pc->ivar1; 18 | } 19 | 20 | // CHECK: @interface current{ 21 | // CHECK: int ivar; 22 | // CHECK: int ivar1; 23 | // CHECK: int ivar2; 24 | // CHECK: } 25 | // CHECK: @end 26 | // CHECK: current *pc; 27 | // CHECK: int foo() { 28 | // CHECK: return pc->ivar2 + (*pc).ivar + pc->ivar1; 29 | // CHECK: } 30 | 31 | -------------------------------------------------------------------------------- /examples/SemaObjC/stmts.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -verify -fsyntax-only -fobjc-exceptions 2 | 3 | struct some_struct; 4 | 5 | @interface NSObject 6 | @end 7 | 8 | // Note: NSException is not declared. 9 | void f0(id x) { 10 | @try { 11 | } @catch (NSException *x) { // expected-error {{unknown type name 'NSException'}} 12 | } @catch (struct some_struct x) { // expected-error {{@catch parameter is not a pointer to an interface type}} 13 | } @catch (int x) { // expected-error {{@catch parameter is not a pointer to an interface type}} 14 | } @catch (static NSObject *y) { // expected-error {{@catch parameter cannot have storage specifier 'static'}} 15 | } @catch (...) { 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /examples/SemaObjC/string.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -verify -fsyntax-only 2 | // RUN: %clang_cc1 %s -verify -fsyntax-only -DDECLAREIT 3 | 4 | // a declaration of NSConstantString is not required. 5 | #ifdef DECLAREIT 6 | @interface NSConstantString; 7 | @end 8 | #endif 9 | 10 | 11 | 12 | id s = @"123"; // simple 13 | id t = @"123" @"456"; // concat 14 | id u = @"123" @ blah; // expected-error {{unexpected token}} 15 | 16 | -------------------------------------------------------------------------------- /examples/SemaObjC/super-property-message-expr.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | @interface SStoreNodeInfo 5 | 6 | @property(nonatomic,readonly,retain) id descriptionShort; 7 | 8 | - (id)stringByAppendingFormat:(int)format, ... ; 9 | 10 | @end 11 | 12 | @interface SStoreNodeInfo_iDisk : SStoreNodeInfo 13 | { 14 | @private 15 | id _etag; 16 | } 17 | @end 18 | 19 | @implementation SStoreNodeInfo_iDisk 20 | - (id) X { return [super.descriptionShort stringByAppendingFormat:1, _etag]; } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /examples/SemaObjC/suspicious-pragma-pack.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -Wpragma-pack-suspicious-include -triple i686-apple-darwin9 -fsyntax-only -I%S/Inputs -verify %s 2 | 3 | #pragma pack (push, 1) // expected-note {{previous '#pragma pack' directive that modifies alignment is here}} 4 | #import "empty.h" // expected-warning {{non-default #pragma pack value changes the alignment of struct or union members in the included file}} 5 | 6 | #pragma pack (pop) 7 | -------------------------------------------------------------------------------- /examples/SemaObjC/synchronized.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | @interface PBXTrackableTaskManager @end 4 | 5 | @implementation PBXTrackableTaskManager 6 | - (id) init { return 0; } 7 | - (void) unregisterTask:(id) task { 8 | @synchronized (self) { 9 | id taskID = [task taskIdentifier]; // expected-warning {{method '-taskIdentifier' not found (return type defaults to 'id')}} 10 | } 11 | } 12 | @end 13 | 14 | 15 | struct x { int a; } b; 16 | 17 | void test1() { 18 | @synchronized (b) { // expected-error {{@synchronized requires an Objective-C object type ('struct x' invalid)}} 19 | } 20 | 21 | @synchronized (42) { // expected-error {{@synchronized requires an Objective-C object type ('int' invalid)}} 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/SemaObjC/synth-provisional-ivars-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | // rdar://8913053 4 | 5 | typedef unsigned char BOOL; 6 | 7 | @interface MailApp 8 | { 9 | BOOL _isAppleInternal; 10 | } 11 | @property(assign) BOOL isAppleInternal; 12 | @end 13 | 14 | static BOOL isAppleInternal() {return 0; } 15 | 16 | @implementation MailApp 17 | 18 | - (BOOL)isAppleInternal { 19 | return _isAppleInternal; 20 | } 21 | 22 | - (void)setIsAppleInternal:(BOOL)flag { 23 | _isAppleInternal= !!flag; 24 | } 25 | 26 | - (void) Meth { 27 | self.isAppleInternal = isAppleInternal(); 28 | } 29 | @end 30 | -------------------------------------------------------------------------------- /examples/SemaObjC/synthesize-setter-contclass.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | 4 | @interface TestClass 5 | { 6 | int _isItIsOrIsItAint; 7 | } 8 | @property (readonly) int itIsOrItAint; 9 | -(void) doSomething; 10 | @end 11 | 12 | @interface TestClass() 13 | @property (readwrite) int itIsOrItAint; 14 | @end 15 | 16 | @implementation TestClass 17 | @synthesize itIsOrItAint = _isItIsOrIsItAint; 18 | 19 | -(void) doSomething 20 | { 21 | int i = [self itIsOrItAint]; 22 | 23 | [self setItIsOrItAint:(int)1]; 24 | } 25 | @end 26 | -------------------------------------------------------------------------------- /examples/SemaObjC/transparent-union.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // expected-no-diagnostics 3 | 4 | typedef union { 5 | struct xx_object_s *_do; 6 | struct xx_continuation_s *_dc; 7 | struct xx_queue_s *_dq; 8 | struct xx_queue_attr_s *_dqa; 9 | struct xx_group_s *_dg; 10 | struct xx_source_s *_ds; 11 | struct xx_source_attr_s *_dsa; 12 | struct xx_semaphore_s *_dsema; 13 | } xx_object_t __attribute__((transparent_union)); 14 | 15 | @interface INTF 16 | - (void) doSomething : (xx_object_t) xxObject; 17 | - (void)testMeth; 18 | @end 19 | 20 | @implementation INTF 21 | - (void) doSomething : (xx_object_t) xxObject {} 22 | - (void)testMeth { struct xx_queue_s *sq; [self doSomething:sq ]; } 23 | @end 24 | -------------------------------------------------------------------------------- /examples/SemaObjC/typo-correction-arc.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple i386-apple-macosx10.10 -fobjc-arc -fsyntax-only -Wno-objc-root-class %s -verify 2 | 3 | typedef unsigned long NSUInteger; 4 | 5 | id nameless; // expected-note{{'nameless' declared here}} 6 | 7 | @interface NSArray 8 | - (instancetype)initWithObjects:(const id[])objects count:(NSUInteger)count; 9 | @end 10 | 11 | @interface I 12 | @property NSArray *array; 13 | - (id)getArrayById:(id)name; 14 | - (void)setArrayValue:(id)array; 15 | @end 16 | 17 | @interface J 18 | - (void)setArray:(id)array; 19 | - (void)setIvarArray; 20 | @end 21 | 22 | @implementation J { 23 | I *i; 24 | } 25 | - (void)setArray:(id)array { // expected-note{{'array' declared here}} 26 | i.array = aray; // expected-error{{use of undeclared identifier 'aray'; did you mean 'array'}} 27 | } 28 | - (void)setIvarArray { 29 | [i setArrayValue:[i getArrayById:nameles]]; // expected-error{{use of undeclared identifier 'nameles'; did you mean 'nameless'}} 30 | } 31 | @end 32 | 33 | -------------------------------------------------------------------------------- /examples/SemaObjC/typo-correction-subscript.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple i386-apple-macosx10.10 -fobjc-arc -fsyntax-only -Wno-objc-root-class %s -verify 2 | 3 | @class Dictionary; 4 | 5 | @interface Test 6 | @end 7 | @implementation Test 8 | // rdar://problem/47403222 9 | - (void)rdar47403222:(Dictionary *)opts { 10 | [self undeclaredMethod:undeclaredArg]; 11 | // expected-error@-1{{no visible @interface for 'Test' declares the selector 'undeclaredMethod:'}} 12 | // expected-error@-2{{use of undeclared identifier 'undeclaredArg}} 13 | opts[(__bridge id)undeclaredKey] = 0; 14 | // expected-error@-1{{use of undeclared identifier 'undeclaredKey'}} 15 | } 16 | @end 17 | -------------------------------------------------------------------------------- /examples/SemaObjC/ucn-objc-string.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 %s -verify -fsyntax-only 2 | // expected-no-diagnostics 3 | @class NSString; 4 | extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))); 5 | 6 | int main() { 7 | NSLog(@"Hi…"); 8 | NSLog(@"Exposé"); 9 | NSLog(@"\U00010400\U0001D12B"); 10 | NSLog(@"hello \u2192 \u2603 \u2190 world"); 11 | NSLog(@"hello → ☃ ← world"); 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /examples/SemaObjC/undeclared-selector.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -Wundeclared-selector -verify -Wno-objc-root-class %s 2 | 3 | typedef struct objc_selector *SEL; 4 | 5 | @interface MyClass 6 | 7 | + (void) methodA; 8 | - (void) methodB; 9 | + (void) methodD; 10 | - (void) methodF; 11 | 12 | @end 13 | 14 | @implementation MyClass 15 | 16 | + (void) methodA {} 17 | - (void) methodB {} 18 | + (void) methodD 19 | { 20 | SEL d = @selector(methodD); /* Ok */ 21 | SEL e = @selector(methodE); 22 | } 23 | 24 | - (void) methodE 25 | { 26 | SEL e = @selector(methodE); /* Ok */ 27 | } 28 | 29 | - (void) methodF 30 | { 31 | SEL e = @selector(methodE); /* Ok */ 32 | } 33 | 34 | @end 35 | 36 | int main (void) 37 | { 38 | SEL a = @selector(methodA); /* Ok */ 39 | SEL b = @selector(methodB); /* Ok */ 40 | SEL c = @selector(methodC); // expected-warning {{undeclared selector 'methodC'}} 41 | SEL d = @selector(methodD); /* Ok */ 42 | SEL e = @selector(methodE); /* Ok */ 43 | return 0; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /examples/SemaObjC/undef-arg-super-method-call.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // rdar://20350364 3 | 4 | @interface NSObject @end 5 | 6 | @interface DBGViewDebuggerSupport : NSObject 7 | + (void)addViewLayerInfo:(id)view; 8 | - (void)addInstViewLayerInfo:(id)view; 9 | @end 10 | 11 | @interface DBGViewDebuggerSupport_iOS : DBGViewDebuggerSupport 12 | @end 13 | 14 | @implementation DBGViewDebuggerSupport_iOS 15 | + (void)addViewLayerInfo:(id)aView; // expected-note {{'aView' declared here}} 16 | { 17 | [super addViewLayerInfo:view]; // expected-error {{use of undeclared identifier 'view'; did you mean 'aView'?}} 18 | } 19 | - (void)addInstViewLayerInfo:(id)aView; // expected-note {{'aView' declared here}} 20 | { 21 | [super addInstViewLayerInfo:view]; // expected-error {{use of undeclared identifier 'view'; did you mean 'aView'?}} 22 | } 23 | @end 24 | -------------------------------------------------------------------------------- /examples/SemaObjC/undef-class-messagin-error.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @interface _Child // expected-note{{'_Child' declared here}} 4 | + (int) flashCache; 5 | @end 6 | 7 | @interface Child (Categ) // expected-error {{cannot find interface declaration for 'Child'; did you mean '_Child'?}} 8 | + (int) flushCache2; 9 | @end 10 | 11 | @implementation OtherChild (Categ) // expected-error {{cannot find interface declaration for 'OtherChild'}} 12 | + (int) flushCache2 { [super flashCache]; } // expected-error {{no @interface declaration found in class messaging of 'flushCache2'}} 13 | @end 14 | -------------------------------------------------------------------------------- /examples/SemaObjC/undef-class-property-error.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @implementation I (C) // expected-error {{cannot find interface declaration for 'I'}} 4 | 5 | + (void)f { 6 | self.m; // expected-error {{member reference base type 'Class' is not a structure or union}} 7 | } 8 | 9 | @end 10 | -------------------------------------------------------------------------------- /examples/SemaObjC/undef-protocol-methods-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | 3 | @protocol P1 4 | - (void) P1proto; // expected-note {{method 'P1proto' declared here}} 5 | + (void) ClsP1Proto; // expected-note {{method 'ClsP1Proto' declared here}} 6 | - (void) DefP1proto; 7 | @end 8 | @protocol P2 9 | - (void) P2proto; // expected-note {{method 'P2proto' declared here}} 10 | + (void) ClsP2Proto; // expected-note {{method 'ClsP2Proto' declared here}} 11 | @end 12 | 13 | @protocol P3 14 | - (void) P3proto; // expected-note {{method 'P3proto' declared here}} 15 | + (void) ClsP3Proto; // expected-note {{method 'ClsP3Proto' declared here}} 16 | + (void) DefClsP3Proto; 17 | @end 18 | 19 | @protocol PROTO 20 | - (void) meth; // expected-note {{method 'meth' declared here}} 21 | - (void) meth : (int) arg1; // expected-note {{method 'meth:' declared here}} 22 | + (void) cls_meth : (int) arg1; // expected-note {{method 'cls_meth:' declared here}} 23 | @end 24 | 25 | @interface INTF 26 | @end 27 | 28 | @implementation INTF // expected-warning 9 {{in protocol '}} 29 | - (void) DefP1proto{} 30 | + (void) DefClsP3Proto{} 31 | @end 32 | -------------------------------------------------------------------------------- /examples/SemaObjC/undefined-protocol-type-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @protocol p1, p4; 4 | @protocol p2 @end 5 | 6 | @interface T 7 | - (T*) meth; // expected-error {{cannot find protocol declaration for 'p3'}} 8 | - (T*) meth1; // expected-error {{cannot find protocol declaration for 'p3'}} 9 | @end 10 | -------------------------------------------------------------------------------- /examples/SemaObjC/unguarded-availability-category-protocol-use.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple arm64-apple-ios10 -Wunguarded-availability -fblocks -fsyntax-only -verify %s 2 | 3 | __attribute__((availability(ios,unavailable))) 4 | @protocol Prot // expected-note {{here}} 5 | 6 | @end 7 | 8 | @interface A 9 | @end 10 | 11 | __attribute__((availability(ios,unavailable))) 12 | @interface A (Cat) // No error. 13 | @end 14 | 15 | __attribute__((availability(tvos,unavailable))) 16 | @interface B @end 17 | @interface B (Cat) // expected-error {{'Prot' is unavailable: not available on iOS}} 18 | @end 19 | -------------------------------------------------------------------------------- /examples/SemaObjC/va-method-1.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | #include 5 | 6 | @interface NSObject @end 7 | @interface XX : NSObject @end 8 | 9 | @implementation XX 10 | - (void)encodeValuesOfObjCTypes:(const char *)types, ... { 11 | va_list ap; 12 | va_start(ap, types); 13 | while (*types) ; 14 | va_end(ap); 15 | } 16 | 17 | @end 18 | 19 | -------------------------------------------------------------------------------- /examples/SemaObjC/validate-attr-swift_attr.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -fsyntax-only %s 2 | 3 | // expected-error@+1 {{'swift_attr' attribute takes one argument}} 4 | __attribute__((swift_attr)) 5 | @interface I 6 | @end 7 | 8 | // expected-error@+1 {{'swift_attr' attribute requires a string}} 9 | __attribute__((swift_attr(1))) 10 | @interface J 11 | @end 12 | -------------------------------------------------------------------------------- /examples/SemaObjC/variable-size-ivar.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only %s -verify 2 | 3 | const int ksize = 42; 4 | int size = 42; 5 | 6 | @interface X 7 | { 8 | int arr1[ksize]; // expected-warning{{variable length array folded to constant array}} 9 | int arr2[size]; // expected-error{{instance variables must have a constant size}} 10 | int arr3[ksize-43]; // expected-error{{array size is negative}} 11 | } 12 | @end 13 | -------------------------------------------------------------------------------- /examples/SemaObjC/warn-assign-property-nscopying.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fobjc-gc -fsyntax-only -verify %s 2 | // RUN: %clang_cc1 -x objective-c++ -fobjc-gc -fsyntax-only -verify %s 3 | 4 | @protocol NSCopying @end 5 | 6 | @interface NSObject 7 | @end 8 | 9 | @interface NSDictionary : NSObject 10 | @end 11 | 12 | @interface INTF 13 | @property NSDictionary* undoAction; // expected-warning {{no 'assign', 'retain', or 'copy' attribute is specified - 'assign' is assumed}} // expected-warning {{default assign attribute on property 'undoAction' which implements NSCopying protocol is not appropriate with}} 14 | @property id okAction; // expected-warning {{no 'assign', 'retain', or 'copy' attribute is specified - 'assign' is assumed}} 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /examples/SemaObjC/warn-cast-of-sel-expr.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value %s 2 | // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wcast-of-sel-type -Wno-unused-value %s 3 | // rdar://12107381 4 | 5 | SEL s; 6 | 7 | SEL sel_registerName(const char *); 8 | 9 | int main() { 10 | (char *)s; // expected-warning {{cast of type 'SEL' to 'char *' is deprecated; use sel_getName instead}} 11 | (void *)s; // ok 12 | (const char *)sel_registerName("foo"); // expected-warning {{cast of type 'SEL' to 'const char *' is deprecated; use sel_getName instead}} 13 | 14 | (const void *)sel_registerName("foo"); // ok 15 | 16 | (void) s; // ok 17 | 18 | (void *const)s; // ok 19 | 20 | (const void *const)s; // ok 21 | 22 | // rdar://12859590 23 | (SEL)sel_registerName("foo"); // ok 24 | } 25 | -------------------------------------------------------------------------------- /examples/SemaObjC/warn-category-method-deprecated.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -verify %s 2 | // rdar://18013929 3 | 4 | @protocol P 5 | - (void)meth; 6 | @end 7 | 8 | @interface I

9 | @end 10 | 11 | @interface I(cat) 12 | - (void)meth __attribute__((deprecated)); // expected-note {{'meth' has been explicitly marked deprecated here}} 13 | @end 14 | 15 | void foo(I *i) { 16 | [i meth]; // expected-warning {{'meth' is deprecated}} 17 | } 18 | -------------------------------------------------------------------------------- /examples/SemaObjC/warn-explicit-call-initialize.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10 -verify %s 2 | // rdar://16628028 3 | 4 | @interface NSObject 5 | + (void)initialize; // expected-note 2 {{method 'initialize' declared here}} 6 | @end 7 | 8 | @interface I : NSObject 9 | + (void)initialize; // expected-note {{method 'initialize' declared here}} 10 | + (void)SomeRandomMethod; 11 | @end 12 | 13 | @implementation I 14 | - (void) Meth { 15 | [I initialize]; // expected-warning {{explicit call to +initialize results in duplicate call to +initialize}} 16 | [NSObject initialize]; // expected-warning {{explicit call to +initialize results in duplicate call to +initialize}} 17 | } 18 | + (void)initialize { 19 | [super initialize]; 20 | } 21 | + (void)SomeRandomMethod { // expected-note {{method 'SomeRandomMethod' declared here}} 22 | [super initialize]; // expected-warning {{explicit call to [super initialize] should only be in implementation of +initialize}} 23 | } 24 | @end 25 | 26 | -------------------------------------------------------------------------------- /examples/SemaObjC/warn-forward-class-attr-deprecated.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2 | // rdar://10290322 3 | 4 | @class ABGroupImportFilesScope; // expected-note {{forward declaration of class here}} 5 | 6 | @interface I1 7 | - (id) filenames __attribute__((deprecated)); // expected-note {{'filenames' has been explicitly marked deprecated here}} 8 | @end 9 | 10 | @interface I2 11 | - (id) Meth : (ABGroupImportFilesScope*) scope; 12 | - (id) filenames __attribute__((deprecated)); 13 | - (id)initWithAccount: (id)account filenames:(id)filenames; 14 | @end 15 | 16 | @implementation I2 17 | - (id) Meth : (ABGroupImportFilesScope*) scope 18 | { 19 | id p = [self initWithAccount : 0 filenames :[scope filenames]]; // expected-warning {{'filenames' may be deprecated because the receiver type is unknown}} 20 | return 0; 21 | } 22 | - (id) filenames { return 0; } 23 | - (id)initWithAccount: (id)account filenames:(id)filenames { return 0; } 24 | @end 25 | -------------------------------------------------------------------------------- /examples/SemaObjC/warn-implicit-atomic-property.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -Wimplicit-atomic-properties -verify -Wno-objc-root-class %s 2 | // rdar://8774580 3 | 4 | @interface Super 5 | @property (nonatomic, readwrite) int P; // OK 6 | @property (atomic, readwrite) int P1; // OK 7 | @property (readwrite) int P2; // expected-note {{property declared here}} 8 | @property int P3; // expected-note {{property declared here}} 9 | @end 10 | 11 | @implementation Super // expected-warning {{property is assumed atomic when auto-synthesizing the property}} 12 | @synthesize P,P1,P2; // expected-warning {{property is assumed atomic by default}} 13 | @end 14 | -------------------------------------------------------------------------------- /examples/SemaObjC/warn-loop-analysis.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -Wloop-analysis -verify %s 2 | // expected-no-diagnostics 3 | 4 | @interface MyArray 5 | - (id)objectAtIndexedSubscript:(unsigned int)idx; 6 | @end 7 | 8 | // Do not warn on objc classes has objectAtIndexedSubscript method. 9 | MyArray *test; 10 | void foo() 11 | { 12 | unsigned int i; 13 | for (i = 42; i > 0;) // No warnings here 14 | (void)test[--i]; 15 | } 16 | -------------------------------------------------------------------------------- /examples/SemaObjC/warn-messaging-id.mm: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class -Wobjc-messaging-id %s 2 | 3 | @interface CallMeMaybe 4 | 5 | - (void)doThing:(int)intThing; 6 | 7 | @property int thing; 8 | 9 | @end 10 | 11 | template 12 | void instantiate(const T &x) { 13 | [x setThing: 22]; // expected-warning {{messaging unqualified id}} 14 | } 15 | 16 | void fn() { 17 | id myObject; 18 | [myObject doThing: 10]; // expected-warning {{messaging unqualified id}} 19 | [myObject setThing: 11]; // expected-warning {{messaging unqualified id}} 20 | instantiate(myObject); // expected-note {{in instantiation}} 21 | } 22 | -------------------------------------------------------------------------------- /examples/SemaObjC/warn-selector-selection.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | 3 | @interface Object 4 | - (void)foo; 5 | @end 6 | 7 | @interface Class1 8 | - (void)setWindow:(Object *)wdw; 9 | @end 10 | 11 | void foo(void) { 12 | Object *obj; 13 | [obj setWindow:0]; // expected-warning{{'Object' may not respond to 'setWindow:'}} 14 | } 15 | -------------------------------------------------------------------------------- /examples/SemaObjC/warn-thread-safety-analysis.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety -Wthread-safety-beta -Wno-objc-root-class %s 2 | 3 | struct __attribute__ ((lockable)) Mutex {}; 4 | 5 | struct Mutex mu1; 6 | 7 | int Foo_fun1(int i) __attribute__ ((exclusive_locks_required((mu1)))) { 8 | return i; 9 | } 10 | 11 | @interface test 12 | @end 13 | 14 | @implementation test 15 | - (void) PR19541 { 16 | Foo_fun1(1); // expected-warning{{calling function 'Foo_fun1' requires holding mutex 'mu1' exclusively}} 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /examples/SemaObjC/warn-unused-exception-param.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions -Wunused-exception-parameter %s 2 | void f0() { 3 | @try {} @catch(id a) {} // expected-warning{{unused exception parameter 'a'}} 4 | } 5 | -------------------------------------------------------------------------------- /examples/SemaObjC/warn-weak-field.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -fobjc-gc -verify -Wno-objc-root-class %s 2 | // RUN: %clang_cc1 -x objective-c++ -triple i386-apple-darwin9 -fsyntax-only -fobjc-gc -verify -Wno-objc-root-class %s 3 | 4 | struct S { 5 | __weak id w; // expected-warning {{__weak attribute cannot be specified on a field declaration}} 6 | __strong id p1; 7 | }; 8 | 9 | @interface I 10 | { 11 | __weak id w; // OK 12 | __strong id LHS; 13 | } 14 | - (void) foo; 15 | @end 16 | @implementation I 17 | - (void) foo { w = 0; LHS = w; } 18 | @end 19 | 20 | int main () 21 | { 22 | struct I { 23 | __weak id w1; // expected-warning {{__weak attribute cannot be specified on a field declaration}} 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /examples/SemaObjC/warn-write-strings.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -verify -fsyntax-only -fconst-strings %s 2 | 3 | // PR4804 4 | char* x = "foo"; // expected-warning {{initializing 'char *' with an expression of type 'const char [4]' discards qualifiers}} 5 | -------------------------------------------------------------------------------- /examples/SemaObjC/weak-property.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -verify -Wno-objc-root-class %s 2 | // rdar://8899430 3 | 4 | @interface WeakPropertyTest { 5 | Class isa; 6 | __weak id value; 7 | id x; // expected-error {{existing instance variable 'x' for __weak property 'x' must be __weak}} 8 | } 9 | @property (weak) id value1; 10 | @property __weak id value; 11 | @property () __weak id value2; 12 | 13 | @property (weak, assign) id v1; // expected-error {{property attributes 'assign' and 'weak' are mutually exclusive}} 14 | @property (weak, copy) id v2; // expected-error {{property attributes 'copy' and 'weak' are mutually exclusive}} 15 | @property (weak, retain) id v3; // expected-error {{property attributes 'retain' and 'weak' are mutually exclusive}} 16 | @property (weak, assign) id v4; // expected-error {{property attributes 'assign' and 'weak' are mutually exclusive}} 17 | 18 | @property () __weak id x; // expected-note {{property declared here}} 19 | @end 20 | 21 | @implementation WeakPropertyTest 22 | @synthesize x; // expected-note {{property synthesized here}} 23 | @dynamic value1, value, value2, v1,v2,v3,v4; 24 | @end 25 | -------------------------------------------------------------------------------- /examples/SemaObjC/writable-property-in-superclass.m: -------------------------------------------------------------------------------- 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s 2 | // expected-no-diagnostics 3 | 4 | @interface MessageStore 5 | @property (assign, readonly) int P; 6 | @end 7 | 8 | @interface MessageStore (CAT) 9 | @property (assign) int P; 10 | @end 11 | 12 | @interface NeXTMbox : MessageStore 13 | @end 14 | 15 | @implementation NeXTMbox 16 | - (void) Meth { self.P = 1; } 17 | @end 18 | 19 | -------------------------------------------------------------------------------- /examples/corpus.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | BASE_DIR=$(git rev-parse --show-toplevel) 4 | 5 | rm "${BASE_DIR}/examples/corpus.m" 2>/dev/null 6 | 7 | cat "${BASE_DIR}/test/corpus/"* | sed -n '/===/,/---/p' | rg -vU '((=)+\n.*\n(=)+)|((-)+\n)' > "${BASE_DIR}/examples/corpus.m" -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tree-sitter-objc", 3 | "version": "1.0.0", 4 | "description": "A tree-sitter parser for Objective-C", 5 | "main": "bindings/node", 6 | "keywords": [ 7 | "parser", 8 | "objective-c", 9 | "tree-sitter" 10 | ], 11 | "scripts": { 12 | "build": "tree-sitter generate && node-gyp build", 13 | "test": "tree-sitter test", 14 | "highlight": "tree-sitter highlight ./examples/corpus.m" 15 | }, 16 | "author": "Jiyee Sheng ", 17 | "license": "MIT", 18 | "dependencies": { 19 | "nan": "^2.14.1" 20 | }, 21 | "devDependencies": { 22 | "tree-sitter-c": "^0.19.0", 23 | "tree-sitter-cli": "^0.20.6" 24 | }, 25 | "tree-sitter": [ 26 | { 27 | "scope": "source.objc", 28 | "file-types": [ 29 | "h", 30 | "m" 31 | ], 32 | "highlights": [ 33 | "queries/highlights.scm", 34 | "node_modules/tree-sitter-c/queries/highlights.scm" 35 | ] 36 | } 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /test/highlight/directives.txt.m: -------------------------------------------------------------------------------- 1 | 2 | @synchronized(self) { 3 | [obj method]; 4 | } 5 | 6 | 7 | @autoreleasepool { 8 | [obj method]; 9 | } 10 | 11 | 12 | @try { 13 | [obj method]; 14 | } @catch (NSException *exception) { 15 | } @finally { 16 | } 17 | 18 | @try { 19 | [obj method]; 20 | } @catch (NSException *exception) { 21 | } 22 | 23 | @try { 24 | [obj method]; 25 | } @finally { 26 | } 27 | 28 | @try { 29 | } @catch (EH1 *x) { 30 | } @catch (EH2 *x) { 31 | } @catch (EH3 *x) { 32 | } 33 | 34 | @try { 35 | } @catch (...) { 36 | } 37 | 38 | 39 | @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"" userInfo:nil]; 40 | 41 | 42 | @compatibility_alias Foo Bar; 43 | 44 | if (@available(iOS 13.0, tvOS 13.0, watchOS 6.0, *)) { 45 | 46 | } 47 | 48 | if (__builtin_available(macos 10.12, *)) { 49 | 50 | } 51 | -------------------------------------------------------------------------------- /test/highlight/extras.txt.m: -------------------------------------------------------------------------------- 1 | 2 | [[NSDateFormatter alloc] init]; 3 | [[NSDateFormatter alloc] init]; 4 | 5 | 6 | extern void OBJC_CLASS_$_f; 7 | 8 | -------------------------------------------------------------------------------- /test/highlight/ifdef.txt.m: -------------------------------------------------------------------------------- 1 | 2 | #ifdef A 3 | @interface UIImageView () 4 | @end 5 | 6 | @interface AA () { 7 | 8 | } 9 | @property (nonatomic) int i; 10 | #if AA 11 | @property (nonatomic) int i; 12 | #elif AA 13 | -(void)test1; 14 | #else 15 | +(void)test2; 16 | #endif 17 | @end 18 | 19 | @implementation AA 20 | 21 | - (void)test { 22 | 23 | } 24 | #ifdef AA 25 | - (void)test { 26 | 27 | } 28 | #else 29 | - (void)test { 30 | 31 | } 32 | #endif 33 | 34 | @end 35 | 36 | #endif 37 | 38 | 39 | NS_ASSUME_NONNULL_BEGIN 40 | @interface ClassName 41 | @property (nonatomic, strong) NSObject *object; 42 | @end 43 | NS_ASSUME_NONNULL_END 44 | 45 | 46 | @interface ClassName 47 | NS_ASSUME_NONNULL_BEGIN 48 | @property (nonatomic, strong) NSObject *object; 49 | NS_ASSUME_NONNULL_END 50 | @end 51 | 52 | -------------------------------------------------------------------------------- /test/highlight/imports.txt.m: -------------------------------------------------------------------------------- 1 | 2 | #import "bar.h" 3 | 4 | 5 | #import 6 | 7 | 8 | #if __has_include() 9 | #import 10 | #endif 11 | 12 | 13 | @import foo.bar 14 | 15 | -------------------------------------------------------------------------------- /test/highlight/properties.txt.m: -------------------------------------------------------------------------------- 1 | 2 | @interface ClassName 3 | 4 | @property () __weak id PROP; 5 | @property (nonatomic, copy) NSArray *array; 6 | @property (nonatomic, weak) IBOutlet UIImageView *view; 7 | @property (nonatomic, setter=setURL:) NSURL *url; 8 | @property (nonatomic, atomic, class, readwrite, null_resettable, NS_NONATOMIC_IOSONLY) NSString *string; 9 | @property (direct, readonly) int intProperty; 10 | 11 | @end 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/highlight/qualifiers.txt.m: -------------------------------------------------------------------------------- 1 | 2 | __block CGFloat scale = 1; 3 | 4 | 5 | NS_VALID_UNTIL_END_OF_SCOPE __strong typeof(self) strongSelf = self; 6 | 7 | 8 | __unsafe_unretained UITableViewCell * cell; 9 | 10 | 11 | static _Atomic(GPBEnumDescriptor*) descriptor = nil; 12 | 13 | 14 | extern CGFloat kHeight() __attribute((weak)); 15 | 16 | -------------------------------------------------------------------------------- /test/highlight/statements.txt.m: -------------------------------------------------------------------------------- 1 | 2 | for (int i = 0; i < 10; i++) { 3 | } 4 | 5 | for (int foo in foos) { 6 | } 7 | 8 | for (NSNumber *foo in foos) { 9 | } 10 | 11 | for (foo in [self foos]) { 12 | } 13 | 14 | for (foo in self.foo) { 15 | } 16 | 17 | for (id foo in self.foos) { 18 | } 19 | 20 | for (id foo in [self foo].foos) { 21 | } 22 | 23 | for (__unsafe_unretained UIView *subview in view.subviews) { 24 | } 25 | 26 | for (NSNumber * _Nonnull foo in foos) { 27 | } 28 | 29 | 30 | if ((quality < 0)) { 31 | return; 32 | } 33 | 34 | --------------------------------------------------------------------------------