From 310031188c679377152eb65b8dc3f92d3799a339 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 1 Oct 2012 11:57:53 +0200 Subject: [PATCH] Fix moc stumbling over gcc __attribute__ extensions Reported by David Faure. In KDE a DEPRECATED macro gets defined in a header file created by cmake. The define is not guarded with #if Q_CC_GNU or similar because at cmake time the compiler is determined. Therefore moc suddenly sees this gcc specific token and stumbles over it. This patch simply defines an empty __attribute__ macro that will expand to nothing and thus become invisible to moc's "C++ parser" after the pre-processing. Change-Id: I4448b9ac3f72b6334e32b27484401fb0fca23a0c Reviewed-by: David Faure Reviewed-by: Olivier Goffart --- src/tools/moc/main.cpp | 8 +++ .../auto/tools/moc/function-with-attributes.h | 57 +++++++++++++++++++ tests/auto/tools/moc/moc.pro | 3 +- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 tests/auto/tools/moc/function-with-attributes.h diff --git a/src/tools/moc/main.cpp b/src/tools/moc/main.cpp index e87c742632..ccdae64738 100644 --- a/src/tools/moc/main.cpp +++ b/src/tools/moc/main.cpp @@ -170,6 +170,14 @@ int runMoc(int _argc, char **_argv) Moc moc; pp.macros["Q_MOC_RUN"]; pp.macros["__cplusplus"]; + + // Don't stumble over GCC extensions + Macro dummyVariadicFunctionMacro; + dummyVariadicFunctionMacro.isFunction = true; + dummyVariadicFunctionMacro.isVariadic = true; + dummyVariadicFunctionMacro.arguments += Symbol(0, PP_IDENTIFIER, "__VA_ARGS__"); + pp.macros["__attribute__"] = dummyVariadicFunctionMacro; + QByteArray filename; QByteArray output; FILE *in = 0; diff --git a/tests/auto/tools/moc/function-with-attributes.h b/tests/auto/tools/moc/function-with-attributes.h new file mode 100644 index 0000000000..1231969078 --- /dev/null +++ b/tests/auto/tools/moc/function-with-attributes.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include + +// test support for gcc attributes with functions + +#if defined(Q_CC_GNU) || defined(Q_MOC_RUN) +#define DEPRECATED __attribute__ ((__deprecated__)) +#else +#define DEPRECATED +#endif + +class FunctionWithAttributes : public QObject +{ + Q_OBJECT +public slots: + DEPRECATED void test() {} + +}; diff --git a/tests/auto/tools/moc/moc.pro b/tests/auto/tools/moc/moc.pro index fd6af68e35..d91ae378da 100644 --- a/tests/auto/tools/moc/moc.pro +++ b/tests/auto/tools/moc/moc.pro @@ -22,7 +22,8 @@ HEADERS += using-namespaces.h no-keywords.h task87883.h c-comments.h backslash-n cxx11-final-classes.h \ cxx11-explicit-override-control.h \ forward-declared-param.h \ - parse-defines.h + parse-defines.h \ + function-with-attributes.h if(*-g++*|*-icc*|*-clang*|*-llvm):!irix-*:!win32-*: HEADERS += os9-newlines.h win-newlines.h