首页 > 解决方案 > 如何使用 clang-tidy 修复预期的 unqualified-id 错误

问题描述

我有以下嵌入式系统的 c++ 代码:

//LIBRARY code:

typedef struct {                                    /*!< (@ 0x48028100) PORT1 Structure                                        */
  __IO uint32_t  OUT;                               /*!< (@ 0x48028100) Port 1 Output Register                                 */
  __O  uint32_t  OMR;                               /*!< (@ 0x48028104) Port 1 Output Modification Register                    */
  __I  uint32_t  RESERVED[2];
  __IO uint32_t  IOCR0;                             /*!< (@ 0x48028110) Port 1 Input/Output Control Register 0                 */
  __IO uint32_t  IOCR4;                             /*!< (@ 0x48028114) Port 1 Input/Output Control Register 4                 */
  __IO uint32_t  IOCR8;                             /*!< (@ 0x48028118) Port 1 Input/Output Control Register 8                 */
  __IO uint32_t  IOCR12;                            /*!< (@ 0x4802811C) Port 1 Input/Output Control Register 12                */
  __I  uint32_t  RESERVED1;
  __I  uint32_t  IN;                                /*!< (@ 0x48028124) Port 1 Input Register                                  */
  __I  uint32_t  RESERVED2[6];
  __IO uint32_t  PDR0;                              /*!< (@ 0x48028140) Port 1 Pad Driver Mode 0 Register                      */
  __IO uint32_t  PDR1;                              /*!< (@ 0x48028144) Port 1 Pad Driver Mode 1 Register                      */
  __I  uint32_t  RESERVED3[6];
  __I  uint32_t  PDISC;                             /*!< (@ 0x48028160) Port 1 Pin Function Decision Control Register          */
  __I  uint32_t  RESERVED4[3];
  __IO uint32_t  PPS;                               /*!< (@ 0x48028170) Port 1 Pin Power Save Register                         */
  __IO uint32_t  HWSEL;                             /*!< (@ 0x48028174) Port 1 Pin Hardware Select Register                    */
} PORT1_Type;

#define PORT1_BASE                      0x48028100UL
#define PORT1                           ((PORT1_Type              *) PORT1_BASE)

// MY MINIMAL EXAMPLE CODE:
...
uint32_t u32SourceAddress = (uint32_t)(&(PORT1->IN)), // error: expected unqualified-id
                                              //  ^
...

当我用 GCC 或 ARMCC 编译这段代码时,它工作得很好。当我使用 clang-tidy 时,我收到一个错误:expected unqualified-id [clang-diagnostic-error] 就可以了。我做错了什么,我该如何解决?

谢谢,莫里茨

编辑:添加了关于基于库的代码和我的代码的评论。

标签: c++compiler-errorsembeddedclang-tidy

解决方案


推荐阅读