4

I'm working in a C project with QtCreator (yes it's primarily for C++, but so far it worked OK for C).

Now I'm getting a red underline on a valid code that compiles fine:

enter image description here

It's basically this unchanged libopencm3 example project for a Virtual COM port.

Can you see some problem in the code, perhaps not fatal, but what could make the editor think it's an error?

I tried substituting struct usb_device_descriptor with an equivalent typedef, but that didn't help.

Error on the second line says "expected }, got .". The closing } is annotated as "extra ;`

Here's how the struct is declared:

/* USB Standard Device Descriptor - Table 9-8 */
struct usb_device_descriptor {
    uint8_t bLength;
    uint8_t bDescriptorType;
    uint16_t bcdUSB;
    uint8_t bDeviceClass;
    uint8_t bDeviceSubClass;
    uint8_t bDeviceProtocol;
    uint8_t bMaxPacketSize0;
    uint16_t idVendor;
    uint16_t idProduct;
    uint16_t bcdDevice;
    uint8_t iManufacturer;
    uint8_t iProduct;
    uint8_t iSerialNumber;
    uint8_t bNumConfigurations;
} __attribute__((packed));
Sam Protsenko
  • 14,045
  • 4
  • 59
  • 75
MightyPork
  • 18,270
  • 10
  • 79
  • 133

1 Answers1

1

Found a workaround:

Change the value for "C" to Clang in this settings page:

enter image description here

(As m.s. points out in the comments, you may have to enable the model first)

Community
  • 1
  • 1
MightyPork
  • 18,270
  • 10
  • 79
  • 133
  • How do you enable "clang" in QtCreator? Those options are greyed out for me (Qt Creator 3.5.1, installed via online installer on Linux) – m.s. Oct 27 '15 at 11:43
  • I installed it from the Arch repository. Do you have clang (and the other optional dependencies) installed? – MightyPork Oct 27 '15 at 15:38
  • I have clang++-3.7 installed on Ubuntu 14.04 via the llvm repository (http://llvm.org/apt/); which other dependencies are there? is there any list you could point me to? – m.s. Oct 27 '15 at 15:40
  • sure, this is an info page for the package I have: https://www.archlinux.org/packages/extra/x86_64/qtcreator/ I have clang 3.7.0-4, qtcreator 3.5.1-1 – MightyPork Oct 27 '15 at 16:00
  • I found out the reason (maybe it was obvious, but not me): The `ClangCodeModel` has to be activated through `Help->About Plugins` ([screenshot](http://i.imgur.com/gYKncZr.png)). After a restart of QtCreator the above mentioned option is available. – m.s. Oct 27 '15 at 19:46
  • 1
    Interesting, I don't remember going to that setting dialog at all. I've added a note in the answer for future googlers. – MightyPork Oct 27 '15 at 20:15