Eclipse CDT indicates syntax error for operator defines - eclipse-cdt

At my company we use C defines like this:
#define AND &&
#define bwAND &
When using this eclipse underlines the expression as if it had a syntax error.
How do I make it understand our logic operator defines?

Your example works in Helios

Related

Q_DECLARE_INTERFACE for plugin creation throws errors all over

Environment:
Framework: Qt 5.12.9
Compiler: MSVC 15.9.28307.1234 (x64)
Debugger: CDB 10.017763.132 (x64)
Standard: C++11
Editor: Qt Creator 4.12.2
OS: Win10 Enterprise 1809
I want to develop an application that can be expanded through plug-ins. Therefore I created a standard library project where I want to define the plug-in interfaces. This library should then be consumed by the main application and its plug-ins.
I read about the Qt plug-in system on the official websites and sought help by duckduckgo-ing, but I'm stuck with these following errors:
vccplugin.h:16:32: error: expected parameter declarator
vccplugin.h:14:23: note: expanded from macro 'VccPlugin_iid'
vccplugin.h:16:32: error: expected ')'
vccplugin.h:14:23: note: expanded from macro 'VccPlugin_iid'
vccplugin.h:16:20: note: to match this '('
vccplugin.h:16:1: error: C++ requires a type specifier for all declarations
Build Issue: C2059: syntax error: 'string'
This is the code:
#ifndef VCCPLUGIN_H
#define VCCPLUGIN_H
#include "VccPluginInterface_global.h"
class VCCPLUGININTERFACE_EXPORT VccPlugin
{
public:
VccPlugin();
~VccPlugin();
void DoeEenTwuk();
};
#define VccPlugin_iid "automation.general.vcc.interface"
Q_DECLARE_INTERFACE(VccPlugin, VccPlugin_iid);
#endif // VCCPLUGIN_H
Also note, I have little experience in both C++ and Qt.
Any help very appreciated,
thanks
I have found the issue. The problem is that the compiler couldn't find the macro, so all I had to add was:
#include <QtPlugin>
Since Q_DECLARE_INTERFACE is defined in QtPlugin. Your example didn't import QtPlugin but was probably imported implicit by another import, probably QMainWindow.
It would have been simpler if I got an error like: "Could not find symbol Q_DECLARE_INTERFACE" if you ask me. Especially since I'm rather blue in this topic.
Thanks for your support #NgocMinhNguyen and others

Unresolved "size" in vector of vectors using operator[] in Eclipse CDT

I am trying to use Eclipse CDT (just for the 'organize includes' functionality) on OS X for a C++ project. The static analyzer (syntax highlighting) doesn't seem to be able to resolve the type of a template operator overload in container classes, such as std::vector and operator[]. Example:
#include <vector>
int main() {
std::vector<std::vector<int> > st = {{0}};
st[0].size(); // Method 'size' could not be resolved
st.front().size(); // no problem
}
This code compiles in g++ and clang++. I am not excited about turning off syntax highlighting completely (what's the point of the IDE?). Any ideas on getting Eclipse CDT (specifically Neon.3 Release (4.6.3) on OS X) to understand this?
EDIT: Updated with a simpler MWE, the problem was not related to using a struct.
EDIT: Added Eclipse CDT version.
Eclipse is not compiling your code every time you type something new but it uses a tool for static StaticAnalysis. Unfortunately that tool is not perfect and things like this happen.
https://wiki.eclipse.org/CDT/designs/StaticAnalysis

C++ namespace "hiding" appearing in the Eclipse parser

Recently I have being working on a project using C++ as the programming language and Eclipse CDT as the programming IDE. The 'Chrono' library is used in the project.
I was trying to define the "<<" stream operator for different time scales like nanoseconds by putting the definitions in the same namespace as chrono, namely "std::chrono". One small example of the code of the header file (Test.hpp) is illustrated as following:
#include <chrono>
#include <iostream>
namespace test{ namespace chrono{
typedef std::chrono::nanoseconds nanoseconds;
}}
namespace std{ namespace chrono{
inline std::ostream& operator<<(std::ostream& s, nanoseconds dur)
{
return s << dur.count() << "ns";
}
}}
The above code together with other parts of the project can be compiled correctly. However, the IDE, Eclipse CDT, keeps complaining "Type 'std::chrono::nanoseconds' could not be resolved" and the auto-completion functionality says "No Default Proposals" for any member variables/functions in the namespace "std::chrono". It looks like that adding new functions into the "std::chrono" namespace in this header file somehow 'hides' other content from the Eclipse's point of views.
The question is what could be the reason leading to such 'error' messages in Eclipse CDT or it is one flaw in my programming? I would appreciate any help or hint from you.
I also copy-past the code into Xcode on the laptop and there is no such error message as in Eclipse CDT.
Additional information:
The os I am using is Mac OS, thus the chrono library is slightly different from that mentioned in the answer. The screenshot of 'chrono.hpp' is as following:
Actually, my CDT has no issue to find the members in the namespace 'std::chrono::'. What confuses me is CDT's behaviour when I add/override members in the namespace 'std::chrono::'. See the following pictures:
Errors appear when I override a member function in the namespace:
Errors do not appear when I do nothing on the namespace:
Any idea on how to solve this problem?
Assumptions about your setup
I believe you have changed your build settings to use -std=c++0x or something similar as the chrono library requires it.
Perhaps you did it like this:
At the top of chrono (header file) there is a bit like this:
#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
#else
so that if you don't have sufficiently new C++ standard, you get a compile error.
Now the problem is the CDT indexer that is used to generate highlighting and code completions does not know you are using __cplusplus >= 201103L. You can see this in this following screenshot that the majority of chrono is inactive because __cplusplus is the wrong value.
This screenshot shows the incorrect value and the errors CDT identifies:
And if you try and code complete, you get the wrong thing too:
How to fix it
To fix the problem, you need to tell CDT that your project uses GCC settings that are different from the default GCC settings. i.e. because of the different standard __cplusplus in particular has the wrong value.
In Project Properties, choose C/C++ General -> Preprocessor Includes and then the Providers tab.
Choose the CDT GCC Built-in Compiler Settings
Uncheck the Use global provider shared between projects
Press OK
Here is a screenshot of what that looks like:
Once you do this, you should see that chrono's inactive sections becomes correct in the editor:
But your source file may still be wrong. You should then rebuild the indexes to update, right-click on the project, choose Index -> Rebuild:
Finally your code should not display properly:
And the code complete should be working too!
History
This is a case where CDT's right hand and left hand don't agree. Historically I believe the reasoning for this is down to performance and trading off indexing every possible variant of compiler/user option, vs having some shared data across the workspace that may be wrong for some projects.

C++ GNU GCC with #define out & colliding

I am working with Code::Blocks and C++ GNU GCC and trying to port my Visual Studio Project to GNU GCC.
And while I am trying to compile I get stuck with my define macro from a Defines.h file:
#define out &
And when compiling I get this error:
error: expected unqualified-id before '=' token
On this line:
// Open for output. Default for #c ofstream and fstream.
static const openmode out = _S_out;
In ios_base.h
As I know, that file is a part of a libstd library. Can I disable it? If so, how can I do that?
My library doesn't requiring any std c++, just c library.
There are two main options:
Don't define a macro using the word out.
Declare the macro after you include all of your headers.
But seriously, a macro named out that becomes & is a pretty awful macro. It's going to make it difficult to understand the code very quickly.

_DEBUG and LLVM 5.0 C++ : Preprocessor Expected value in expression

I'm having issues with XCode, LLVM and the _DEBUG definition. Or more specifically it seems to be something with underscore.
This is the second time I'm getting an error like this. This time Im compiling against PhysX lib.
/Library/Frameworks/PhysX.framework/Versions/3.2.1/include/foundation/PxPreprocessor.h:316:35:
Expected value in expression
The line it's complaining about:
#if !defined(PX_CHECKED) && _DEBUG
And it points at right after the _DEBUG. If I remove the underscore it compiles fine (I did that on a similiar library last time as well, see http://www.ogre3d.org/forums/viewtopic.php?f=2&t=78990). But now Im feeling uneasy about this error. What is causing it and what does it mean?
Settings:
Dialect: C++11, libc++ (Tried different ones, like GNUC++11
Max OSX 10.8
XCode 5
LLVM 5.0
Names that begin with an underscore are reserved for the implementation. Instead, use names that don't begin with an underscore unless you are specifically trying to access some implementation-specific feature.
Use defined() on implementation specific macros:
#if !defined(PX_CHECKED) && defined(_DEBUG)
If there's some reason you are expecting this to work, you haven't explained what it is. There is no reason this should work. What are you expecting it to do?