Giter VIP home page Giter VIP logo

cdecl's Introduction

cdecl

Introduction

I’m still uncertain about the language declaration syntax, where in declarations, syntax is used that mimics the use of the variables being declared. It is one of the things that draws strong criticism, but it has a certain logic to it.

— Dennis M. Ritchie, Creator of C

I consider the C declarator syntax an experiment that failed.

— Bjarne Stroustrup, Creator of C++

cdecl (see-deh-kull) is a program primarily for composing and deciphering C (or C++) declarations or casts, aka ‘‘gibberish.’’ It can be used interactively on a terminal or accept input from either the command line or standard input. For example:

cdecl> explain int *const (*p)[4]
declare p as pointer to array 4 of constant pointer to integer

cdecl> declare p as pointer to const pointer to const char
const char *const *p;

Additionally, cdecl is also for developing and debugging C preprocessor macros by performing expansion step-by-step. For example:

cdecl> #define NAME2_HELPER(A,B)         A ## B
cdecl> #define NAME2(A,B)                NAME2_HELPER(A,B)
cdecl> expand NAME2(var_, __LINE__)
NAME2(var_, __LINE__) => NAME2_HELPER(A,B)
| A => var_
| B => __LINE__
| | __LINE__ => 42
| B => 42
NAME2(var_, 42) => NAME2_HELPER(var_,42)
| NAME2_HELPER(var_, 42) => A ## B
| NAME2_HELPER(var_, 42) => var_ ## 42
| NAME2_HELPER(var_, 42) => var_42
NAME2(var_, 42) => var_42

This codebase fixes virtually all the deficiencies in earlier versions as well as adds many new features, most notably:

  • Using GNU Autotools for building.
  • Command-line long-options.
  • Distinguishes among K&R C, C89, C95, C99, C11, C17, C23, C++98, C++03, C++11, C++14, C++17, C++20, and C++23.
  • Support for C89 const, restrict, and volatile qualifiers.
  • Support for C99 static, type-qualified, and variable length array function parameters.
  • Support for C99 extensions Embedded C and Unified Parallel C.
  • Support for inline function and variable declarations.
  • Support for typedef declarations.
  • Pre-defined typedef declarations for many POSIX and standard library types (FILE, in_addr_t, int8_t, pid_t, pthread_t, ptrdiff_t, size_t, std::ostream, std::string, etc.), and all Microsoft Windows types.
  • Support for Microsoft Windows calling conventions.
  • Support for variadic function parameters.
  • Support for C and C++ alternative tokens (and, and_eq, etc.).
  • Support for C++ constructors, destructors, mutable data members, namespaces and scoped names, new-style casts, pointers to members, throw, overloaded operators, and friend, virtual and pure virtual member function declarations, and user-defined conversion operators.
  • Support for C++11 auto (as a deduced type), constexpr, enum class, fixed-type enumerations, final, lambdas, noexcept, override, rvalue references, user-defined literals, using (as a typedef synonym), the function trailing return-type syntax, and ref-qualified member function declarations.
  • Support for C++17 structured bindings.
  • Support for C++20 abbreviated function template parameter pack, constrained auto, consteval, constinit, and export declarations.
  • Support for C++23 explicit object parameters.
  • Support for C++ [[carries_dependency]], [[deprecated]], [[maybe_unused]], [[nodiscard]], and [[noreturn]] attribute specifiers.
  • Better warning and error messages complete with location information, color, and "Did you mean ...?" suggestions.

Installation

The git repository contains only the necessary source code. Things like configure are derived sources and should not be included in repositories. If you have autoconf, automake, and m4 installed, you can generate configure yourself by doing:

./bootstrap

You will also need flex and bison (lex and yacc won't do); or you can download a released version that contains configure and the generated lexer and parser. In either case, then follow the generic installation instructions given in INSTALL.

If you would like to generate code coverage reports, you will also need gcov (part of gcc) and lcov; then instead do:

./configure --enable-coverage
make check-coverage

If you would like to generate the developer documentation, you will also need Doxygen; then do:

make doc                            # or: make docs

Licensing

cdecl was originally written by Graham Ross sometime in the mid-1980s. Tony Hansen, a major contributor, posted the source code with his changes (parts 1 & 2) to comp.sources.unix in 1988.

The source files have never had either a copyright notice or license. Attempts have been made independently by several people to contact Graham over the years to clear-up the licensing issue, all without success.

In 1996, David Conrad made contributions for version 2.5 and wrote:

I have no reason to believe there are any limitations on [cdecl's] use, and strongly believe it to be in the Public Domain.

(See the included README-2.5.txt for David's full comments.)

Something in the Public Domain allows anyone to do whatever they want with it. Assuming that David is correct and that cdecl is in the Public Domain, I therefore am licensing cdecl 3.0 (and later) under the GNU General Public License, v3.

However, even if you do not assume that the original version of cdecl is in the public domain, copyright law allows for "fair use" for which there are four factors to consider:

  1. Purpose and character of the use, including whether the use is of a commercial nature or is for nonprofit educational purposes.

    My version of cdecl is not of a commercial nature and is for nonprofit educational purposes.

  2. Nature of the copyrighted work.

    The purpose of cdecl is to provide a tool for C and C++ developers. Unlike, say, a literary work, the output of cdecl based on user input is what is of primary importance, not the source code itself.

  3. Amount and substantiality of the portion used in relation to the copyrighted work as a whole.

    The table below shows a comparison between Hansen's version of cdecl and a recent version of my cdecl. Hansen's files on the left map to my files on the right, both with total numbers of lines of code and the perecentage of my lines that Hansen's version is:

    Hansen's Lines Lucas's Lines %
    cdgram.y 855 parser.y 9718 8.8%
    cdlex.l 75 lexer.l 1840 4.1%
    cdecl.c 1014 *.[ch] 42853 2.4%
    Total 1944 54411 3.6%

    Hansen's version of cdecl accounts for only 3.6% of a recent total of the number of lines of code of my version of cdecl. Additionally, of that small percentage, there are very likely no lines that haven't been modified substantially.

  4. Effect of the use upon the potential market for or value of the copyrighted work.

    Given that there are millions of C and C++ developers, the potential market is huge; however, all versions of cdecl were released as open-source and distributed widely for free. Additionally, cdecl prior to 3.0 has limited value since it has not kept pace with the evolution of C and C++. Hence, it has no market value.

Note, however, that I am not a lawyer; but my layman's anaysis seems reasonable.

Notice of Non-Affiliation

The site https://github.com/paul-j-lucas/cdecl is the only offical site for cdecl versions 3.0 and later. I am not affiliated with any other site you might find some version of cdecl on.

Paul J. Lucas
San Francisco Bay Area, California, USA
13 June 2024

cdecl's People

Contributors

jengelh avatar mjsir911 avatar paul-j-lucas avatar polluks avatar ridiculousfish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cdecl's Issues

FTBFS 12.0

gcc -DHAVE_CONFIG_H -I.  -I../lib -I../lib -I/include      -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -g  -Wcast-align -Wconversion -Wextra -Wfloat-equal -Wimplicit-fallthrough -Wredundant-decls -Wshadow -Wsign-compare -Wsign-conversion -Wuninitialized -Wunreachable-code -Wunused -Wwrite-strings -c -o parser.o parser.c
In file included from c_ast.h:35,
                 from parser.y:36:
c_operator.h:243:1: warning: 'nodiscard' attribute ignored [-Wattributes]
  243 | bool c_oper_is_ambiguous( c_operator_t const *op ) {
      | ^~~~
In file included from c_operator.h:36:
c_operator.h:243:1: error: expected identifier or '(' before '_Bool'
  243 | bool c_oper_is_ambiguous( c_operator_t const *op ) {
      | ^~~~

The source at that location is

C_OPERATOR_H_INLINE NODISCARD
bool c_oper_is_ambiguous( c_operator_t const *op ) {
  return op->params_min == 0 && op->params_max == 2;
}

The culprit would appear to be:

config.h:# define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]

Because this test snippet also wouldn't compile:

inline [[__nodiscard__]] void f(){}

result

x.c:1:1: warning: ‘nodiscard’ attribute ignored [-Wattributes]
    1 | inline [[__nodiscard__]] void f(){}
      | ^~~~~~
x.c:1:26: error: expected identifier or ‘(’ before ‘void’
    1 | inline [[__nodiscard__]] void f(){}
      |                          ^~~~

Compiler is

gcc version 12.1.1 20220721 [revision 4f15d2234608e82159d030dadb17af678cfad626] (SUSE Linux) 

flex 2.5.27

...part of my SDK

Making all in src
make[1]: Entering directory '/RAM/cdecl-master/src'
/bin/sh ../ylwrap parser.y y.tab.c parser.c y.tab.h `echo parser.c | sed -e s/cc$/hh/ -e s/cpp$/hpp/ -e s/cxx$/hxx/ -e s/c++$/h++/ -e s/c$/h/` y.output parser.output -- bison -o y.tab.c -d
updating parser.h
/bin/sh ../ylwrap lexer.l lex.yy.c lexer.c -- flex
/RAM/cdecl-master/src/lexer.l:32: unrecognized '%' directive
/RAM/cdecl-master/src/lexer.l:33: bad character: #
/RAM/cdecl-master/src/lexer.l:33: unknown error processing section 1
/RAM/cdecl-master/src/lexer.l:33: unknown error processing section 1
/RAM/cdecl-master/src/lexer.l:33: bad character: "
/RAM/cdecl-master/src/lexer.l:33: unknown error processing section 1
/RAM/cdecl-master/src/lexer.l:33: bad character: .
/RAM/cdecl-master/src/lexer.l:33: unknown error processing section 1
/RAM/cdecl-master/src/lexer.l:33: bad character: "
/RAM/cdecl-master/src/lexer.l:33: bad character: /
/RAM/cdecl-master/src/lexer.l:33: bad character: *
/RAM/cdecl-master/src/lexer.l:33: unknown error processing section 1
/RAM/cdecl-master/src/lexer.l:33: unknown error processing section 1
/RAM/cdecl-master/src/lexer.l:33: unknown error processing section 1
/RAM/cdecl-master/src/lexer.l:33: bad character: *
/RAM/cdecl-master/src/lexer.l:33: bad character: /
/RAM/cdecl-master/src/lexer.l:34: bad character: }
make[1]: *** [Makefile:1853: lexer.c] Error 1
make[1]: Leaving directory '/RAM/cdecl-master/src'
make: *** [Makefile:1459: all-recursive] Error 1

--west-decl=t for "pointer to const pointer to ..." has no effect

Run-time Issue

What was the input given to cdecl?

c++decl --west-decl=t 'declare p as pointer to const pointer to int'

What output did you expect to be given by cdecl?

int* const* p;

What output was actually given by cdecl?

int *const *p;

Additional Comments

For:

c++decl --west-decl=t 'declare p as pointer to pointer to int'

you correctly get:

int** p;

but when you insert const for the second pointer, --west-decl=t has no effect, i.e., the *'s are "east."

Invalid function declarator accepted as valid

For example int foo()()() is comprehended as "declare foo as function returning function returning function returning int", but it's an invalid declarator and won't pass compilation, please help thanks!

Autoconf: `AX_CFLAGS_GCC_OPTION` deprecation, crustiness, warnings, etc

So, I was building this project for the first time today, and I was a bit overwhelmed with the quantity of autoconf warnings I saw.

Basically a ton of repetitions of these two chunks:

configure.ac:188: warning: The macro `AC_LANG_C' is obsolete.
configure.ac:188: You should run autoupdate.
./lib/autoconf/c.m4:72: AC_LANG_C is expanded from...
lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
./lib/autoconf/general.m4:2248: AC_CACHE_VAL is expanded from...
./lib/autoconf/general.m4:2269: AC_CACHE_CHECK is expanded from...
m4/ax_cflags_gcc_option.m4:118: AX_CFLAGS_GCC_OPTION_NEW is expanded from...
m4/ax_cflags_gcc_option.m4:187: AX_CFLAGS_GCC_OPTION is expanded from...
configure.ac:188: the top level
configure.ac:188: warning: The macro `AC_TRY_COMPILE' is obsolete.
configure.ac:188: You should run autoupdate.
./lib/autoconf/general.m4:2846: AC_TRY_COMPILE is expanded from...
lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
./lib/autoconf/general.m4:2248: AC_CACHE_VAL is expanded from...
./lib/autoconf/general.m4:2269: AC_CACHE_CHECK is expanded from...
m4/ax_cflags_gcc_option.m4:118: AX_CFLAGS_GCC_OPTION_NEW is expanded from...
m4/ax_cflags_gcc_option.m4:187: AX_CFLAGS_GCC_OPTION is expanded from...
configure.ac:188: the top level

(Contrary to what the latter warning says, autoupdate doesn't actually do anything.)

I did notice that AX_CFLAGS_GCC_OPTION is very obsolete... like, very very obsolete... like, removed-from-autoconf-archive-in-2011 obsolete. So that would tend to explain why it's using really old macros.

However I also noticed that the version of AX_CFLAGS_GCC_OPTION in this repo isn't even the most recent version of it before it was deprecated and then removed. There's a somewhat-newer (well, 2011, anyway) version of the file that is greatly simplified and which also doesn't trigger any obsolete macro warnings. Here's a link to that very-last version:
http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=blob_plain;f=m4/ax_cflags_gcc_option.m4;hb=88f3e44a62f122149c849044ed5cd63b48d6fda3

I dropped it in over the older version included in the repo, and aside from all the autoconf warnings clearing up, the behavior appeared to be identical (I tested with both GCC and Clang and it seemed to have the same results as before).

So, if abandoning AX_CFLAGS_GCC_OPTION entirely isn't super appealing, you should still be able to at least use a newer old macro version and end up with at least somewhat less crustiness overall. 👍

spurious error from cdecl regarding __stdcall pointers

Given the query

cdecl> declare foo as pointer to pointer to stdcall function (void) returning int

cdecl correctly responds

int (__stdcall **foo)(void);

However, when the output is given back to cdecl

cdecl> explain int (__stdcall **foo)(void)

it erroneously complains

error: "__stdcall": can be used only for functions and pointers to function

Note that the given expression is accepted without error by Microsoft's x86 compiler.

Bison/Flex: Posix Yacc warnings

I don't know if you want to fix these, but I get this warning set on 6.4 on FreeBSD:

/bin/sh ../ylwrap lexer.l lex.yy.c lexer.c -- flex
--- parser.c ---
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:29.1-7: warning: POSIX Yacc does not support %expect [-Wyacc]
%expect 27
^~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:719.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_QMARK_COLON "?:"
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:726.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_EXCLAM_EQ "!="
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:727.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_PERCENT_EQ "%="
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:728.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_AMPER2 "&&"
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:729.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_AMPER_EQ "&="
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:730.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_STAR_EQ "="
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:731.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_PLUS2 "++"
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:732.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_PLUS_EQ "+="
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:733.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_MINUS2 "--"
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:734.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_MINUS_EQ "-="
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:735.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_ARROW "->"
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:736.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_SLASH_EQ "/="
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:737.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_LESS2 "<<"
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:738.35-39: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_LESS2_EQ "<<="
^~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:739.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_LESS_EQ "<="
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:740.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_EQ2 "=="
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:741.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_GREATER_EQ ">="
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:742.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_GREATER2 ">>"
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:743.35-39: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_GREATER2_EQ ">>="
^~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:744.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_CIRC_EQ "^="
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:745.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_PIPE_EQ "|="
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:746.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_PIPE2 "||"
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:777.35-39: warning: POSIX Yacc does not support string literals [-Wyacc]
%token Y_ELLIPSIS "..." /
for varargs /
^~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:805.35-39: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_ARROW_STAR "->
"
^~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:810.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_COLON2 "::"
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:811.35-39: warning: POSIX Yacc does not support string literals [-Wyacc]
%token Y_COLON2_STAR "::"
^~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:820.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_DOT_STAR ".
"
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:851.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token Y_LBRACKET2 "[[" /* for attribute specifiers /
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:852.35-38: warning: POSIX Yacc does not support string literals [-Wyacc]
%token Y_RBRACKET2 "]]" /
for attribute specifiers /
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:884.39-43: warning: POSIX Yacc does not support string literals [-Wyacc]
%token <oper_id> Y_LESS_EQ_GREATER "<=>"
^~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1048.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; FREE( $$ ); } any_name
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1049.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; FREE( $$ ); } any_name_expected
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1050.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; FREE( $$ ); } name_expected
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1051.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; FREE( $$ ); } name_opt
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1052.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; FREE( $$ ); } set_option_name
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1053.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; FREE( $$ ); } Y_LANG_NAME
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1054.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; FREE( $$ ); } Y_NAME
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1057.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; c_sname_free( &$$ ); } of_scope_english
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1058.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; c_sname_free( &$$ ); } of_scope_list_english
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1059.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; c_sname_free( &$$ ); } of_scope_list_english_opt
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1060.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; c_sname_free( &$$ ); } scope_sname_c_opt
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1061.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; c_sname_free( &$$ ); } sname_c
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1062.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; c_sname_free( &$$ ); } sname_c_expected
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1063.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; c_sname_free( &$$ ); } sname_c_opt
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1064.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; c_sname_free( &$$ ); } sname_english
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1065.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; c_sname_free( &$$ ); } sname_english_expected
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1066.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; c_sname_free( &$$ ); } typedef_sname_c
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1067.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; c_sname_free( &$$ ); } any_sname_c
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1068.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; c_sname_free( &$$ ); } any_sname_c_expected
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1069.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; c_sname_free( &$$ ); } Y_CONSTRUCTOR_SNAME
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:1070.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { DTRACE; c_sname_free( &$$ ); } Y_DESTRUCTOR_SNAME
^~~~~~~~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:2631.5-9: warning: POSIX Yacc does not support string literals [-Wyacc]
| "..."
^~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:2899.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "&&" { $$ = T_RVALUE_REFERENCE; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:2923.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "->" type_c_ast { type_push( $2.ast ); } cast_c_ast_opt
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:3177.22-25: warning: POSIX Yacc does not support string literals [-Wyacc]
| /
type_c_ast / "&&"
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:3355.5-9: warning: POSIX Yacc does not support string literals [-Wyacc]
| "..."
^~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:3665.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
: "[[" attribute_name_list_c_type_opt "]]"
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:3665.41-44: warning: POSIX Yacc does not support string literals [-Wyacc]
: "[[" attribute_name_list_c_type_opt "]]"
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4079.34-37: warning: POSIX Yacc does not support string literals [-Wyacc]
| /
type_c_ast / any_typedef "::" sname_c
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4103.34-37: warning: POSIX Yacc does not support string literals [-Wyacc]
| /
type_c_ast / any_typedef "::" typedef_sname_c
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4161.13-16: warning: POSIX Yacc does not support string literals [-Wyacc]
| sname_c "::"
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4173.17-20: warning: POSIX Yacc does not support string literals [-Wyacc]
| any_typedef "::"
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4188.13-16: warning: POSIX Yacc does not support string literals [-Wyacc]
: sname_c "::" Y_NAME
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4202.13-16: warning: POSIX Yacc does not support string literals [-Wyacc]
| sname_c "::" any_typedef
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4279.21-24: warning: POSIX Yacc does not support string literals [-Wyacc]
: typedef_sname_c "::" sname_c
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4291.21-24: warning: POSIX Yacc does not support string literals [-Wyacc]
| typedef_sname_c "::" any_typedef
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4370.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "!=" { $$ = OP_EXCLAM_EQ ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4372.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "%=" { $$ = OP_PERCENT_EQ ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4374.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "&&" { $$ = OP_AMPER2 ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4375.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "&=" { $$ = OP_AMPER_EQ ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4378.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "
=" { $$ = OP_STAR_EQ ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4380.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "++" { $$ = OP_PLUS2 ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4381.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "+=" { $$ = OP_PLUS_EQ ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4384.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "--" { $$ = OP_MINUS2 ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4385.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "-=" { $$ = OP_MINUS_EQ ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4386.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "->" { $$ = OP_ARROW ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4387.5-9: warning: POSIX Yacc does not support string literals [-Wyacc]
| "->" { $$ = OP_ARROW_STAR ; }
^~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4389.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| ".
" { $$ = OP_DOT_STAR ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4391.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "/=" { $$ = OP_SLASH_EQ ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4392.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "::" { $$ = OP_COLON2 ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4394.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "<<" { $$ = OP_LESS2 ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4395.5-9: warning: POSIX Yacc does not support string literals [-Wyacc]
| "<<=" { $$ = OP_LESS2_EQ ; }
^~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4396.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "<=" { $$ = OP_LESS_EQ ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4397.5-9: warning: POSIX Yacc does not support string literals [-Wyacc]
| "<=>" { $$ = OP_LESS_EQ_GREATER ; }
^~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4399.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "==" { $$ = OP_EQ2 ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4401.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| ">>" { $$ = OP_GREATER2 ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4402.5-9: warning: POSIX Yacc does not support string literals [-Wyacc]
| ">>=" { $$ = OP_GREATER2_EQ ; }
^~~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4403.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| ">=" { $$ = OP_GREATER_EQ ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4404.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "?:" { $$ = OP_QMARK_COLON ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4407.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "^=" { $$ = OP_CIRC_EQ ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4409.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "||" { $$ = OP_PIPE2 ; }
^~~~
/wrkdirs/usr/ports/devel/cdecl/work/cdecl-cdecl-6.4/src/parser.y:4410.5-8: warning: POSIX Yacc does not support string literals [-Wyacc]
| "|=" { $$ = OP_PIPE_EQ ; }
^~~~

10.3 FTBFS

[   22s] gcc -DHAVE_CONFIG_H -I.  -I../lib -I../lib -I/include   -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -g  -Wcast-align -Wconversion -Wextra -Wfloat-equal -Wimplicit-fallthrough -Wredundant-decls -Wshadow -Wsign-compare -Wsign-conversion -Wuninitialized -Wunreachable-code -Wunused -Wwrite-strings -c -o lexer.o lexer.c
[   22s] In file included from lexer.c:18:
[   22s] ../lib/string.h:959:1: error: expected ',' or ';' before '_GL_ATTRIBUTE_MALLOC'
[   22s]   959 | _GL_FUNCDECL_SYS (strdup, char *,
[   22s]       | ^~~~~~~~~~~~~~~~

https://build.opensuse.org/package/live_build_log/devel:tools/cdecl/openSUSE_Tumbleweed/x86_64

gcc -E has to say

extern int _gl_cxxalias_dummy;
# 959 "../lib/string.h" 3
extern char * strdup (char const *__s) __attribute__ ((__nonnull__ (1))) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE

Sometimes incorrect parse of `C(C&)`

A declaration like:

c++decl> explain C(C const&)
declare C as constructor (reference to constant C)

(where C has not been predeclared) works because the lexer returns C as a NAME and the parser matches it here:

pc99_func_or_constructor_decl_c
  : Y_NAME '(' param_list_c_ast_opt ')' noexcept_c_stid_opt func_equals_c_stid_opt

In C++, a NAME followed by ( declares an in-class constructor, so we interpret it as such.

However, if C is predeclared, then it doesn't work:

c++decl> class C
c++decl> explain C(C const&)
                          ^
12: syntax error: "&": ')' expected

The reason is because the lexer returns C as a type name and the parser tries to match it here:

typed_declaration_c
  : type_c_ast decl_list_c_opt

as an ordinary typed declaration (which is wrong). The reason is because C++ grammar is ambiguous:

C(x)    // declare x as C (with unnecessary parentheses)
C(C&)   // declare C as constructor

There's no easy fix for this.

Support for alternative FLEX and YACC implementations?

cdecl currently checks for flex providing the LEX implementation

cdecl/configure.ac

Lines 58 to 62 in c3d7878

AX_PROG_FLEX(
[AC_DEFINE([LEX], [flex], ["flex" found])],
AS_IF([test ! -f "$srcdir/src/lexer.c"],
[AC_MSG_ERROR([required program "flex" not found])])
)

and bison providing the YACC implementation

cdecl/configure.ac

Lines 63 to 67 in c3d7878

AX_PROG_BISON(
[AC_DEFINE([YACC], [bison], ["bison" found])],
AS_IF([test ! -f "$srcdir/src/parser.c"],
[AC_MSG_ERROR([required program "bison" not found])])
)

due packaging cdecl in Gentoo, the question came up how far cdecl supports alternative implementations (Gentoo (bug # 879233)[https://bugs.gentoo.org/879233]). Namely reflex and byacc.

Is the hard dependency on flex and bison deliberate, or is the strong check in configure.ac via AX_PROG_FLEX / AX_PROG_BISON unintentional and could be replaced with AC_PROG_LEX / AC_PROG_YACC?

bison 3.3.2

Please check the minimum required version of bison

$ make
/bin/bash ../ylwrap parser.y y.tab.c parser.c y.tab.h `echo parser.c | sed -e s/cc$/hh/ -e s/cpp$/hpp/ -e s/cxx$/hxx/ -e s/c++$/h++/ -e s/c$/h/` y.output parser.output -- bison -o y.tab.c -d
/home/stefan/g/cdecl/src/parser.y:29.1-41: error: %define variable 'api.header.include' is not used
 %define api.header.include { "parser.h" }
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make: *** [Makefile:1855: parser.c] Error 1

cdecl fails to round-trip "pointer to function returning pointer to array" in function parameter

Consider the following:

cdecl> declare foo as pointer to function returning pointer to array of char
char (*(*foo)())[];
cdecl> explain char (*(*foo)())[]
declare foo as pointer to function returning pointer to array of char

So far, so good. Now as function parameter:

cdecl> declare foo as function (pointer to function returning pointer to array of char) returning int
int foo(char (*(*)())[]);

Also good; but when fed back to cdecl an error occurs:

cdecl> explain int foo(char (*(*)())[])
                                    ^
30: error: function returning array; did you mean function returning pointer?

Incorrect explanation for void f(int ())

Currently:

cdecl> explain void f( int() )
declare f as function (int) returning void

which is wrong. It should be:

declare f as function (pointer to function returning int) returning void

because C allows pointer-to-function arguments to be written omitting the (*):

void f( int (*g)() );  // arg = g as pointer to function returning int
void f( int   g () );  // same

So it follows when you omit the argument name:

void f( int (*)() );  // arg = pointer to function returning int
void f( int    () );  // same

but cdecl treats the () as spurious parentheses as in:

int (x);  // same as: int x;

which in the case of function arguments is wrong.

This is non-trival to fix because:

cdecl> explain void f( int (g) );
declare f as function (g as int) returning void

is correct since the () are spurious in this case. That is:

void f( int (g   ) ); // g as int -- with spurious ()
void f( int (    ) ); // unnamed parameter as pointer to function returning int
void f( int (void) ); // unnamed parameter as pointer to function returning int

which is bizarre, but a consequence of allowing the (*) to be omitted for pointers-to-function.

Fortunately, this bug is in a very obscure corner of C. (Personally, I always write out pointer-to-function arguments in "long form" with the (*).)

Misses reporting presence of array, and pointing out that its invalid declaration (array of functions is not allowed)

First I installed homebrew's version of cdecl which uses https://github.com/ridiculousfish/cdecl-blocks. For the following declarations (taken from here), it produces the correct explanation but misses reporting that the declarations have error: array of functions is not allowed.

Then I tried your GitHub repo as it seems like its actively maintained. Your cdecl program completely misses reporting existence of an array in the explanation, and it doesn't flag any problem with the declaration either (i.e array of functions is not allowed. Btw, thanks for working on this, I had been looking for something like this for a while.

~/test/paul-j-lucas/cdecl explain 'int *var[5](int, int);'
declare var as function (int, int) returning pointer to int
        ^^^^^^^^^^^^^^^
❯ ~/test/ridiculousfish/cdecl explain 'int *var[5](int, int);'
declare var as array 5 of function (int, int) returning pointer to int
        ^^^^^^^^^^^^
❯ ~/test/paul-j-lucas/cdecl explain 'struct both *var[5](struct both, struct both);'
declare var as function (structure both, structure both) returning pointer to structure both
        ^^^^^^^^^^^^^^^
❯ ~/test/ridiculousfish/cdecl explain 'struct both *var[5](struct both, struct both);'
declare var as array 5 of function (struct both, struct both) returning pointer to struct both
        ^^^^^^^^^^^^

As a sidenote, the source I took the sample declarations from seems like a decent place to learn such declarations, and perhaps do basic testing against. Also, the int version is my simplified version derived from the struct both version you will find on that link.

Unable to declare an explanation with "ptr"

The explain command's output is normally usable a command in its own right (and vice-versa), but this falls on its feet when the variable name is called ptr:

c++decl> explain void *ptr
declare ptr as pointer to void
c++decl> declare ptr as pointer to void
                 ^
18: syntax error: "ptr": name or operator expected

Add support for using type alias.

Are there any plans to add C++ using type aliases?

c++decl> explain typedef int v3[3];
declare v3 as type array 3 of int
c++decl> explain using v3 = int[3];
                 ^
9: syntax error: "using": unexpected token
c++decl>

Warnings with clang version 12.0.1/FreeBSD 14-CURRENT

with the 11.4 version.

--- getopt.o ---
getopt.c:208:21: warning: implicit conversion changes signedness: 'long' to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
  namelen = nameend - d->__nextchar;
          ~ ~~~~~~~~^~~~~~~~~~~~~~~
getopt.c:255:34: warning: implicit conversion changes signedness: 'int' to 'unsigned long' [-Wsign-conversion]
                        else if ((ambig_set = malloc (n_options)) == NULL)
                                              ~~~~~~  ^~~~~~~~~
getopt.c:263:30: warning: implicit conversion changes signedness: 'int' to 'unsigned long' [-Wsign-conversion]
                            memset (ambig_set, 0, n_options);
                            ~~~~~~                ^~~~~~~~~
getopt.c:369:16: warning: variable 'option_index' may be uninitialized when used here [-Wconditional-uninitialized]
    *longind = option_index;
               ^~~~~~~~~~~~
getopt.c:204:19: note: initialize the variable 'option_index' to silence this warning
  int option_index;
                  ^
                   = 0
4 warnings generated.
--- strnlen1.o ---
strnlen1.c:32:25: warning: implicit conversion changes signedness: 'long' to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
    return end - string + 1;
    ~~~~~~ ~~~~~~~~~~~~~^~~
1 warning generated.

JFYI.

Reword member function reference qualifiers

This is a proposal for some new wording regarding member functions' cv-qualifiers and ref-qualifiers, stemming from a discussion I had on ##c++ IRC. For the following commands, I suggest new wording:

c++decl> explain int (K::*p)() const;
declare p as pointer to member of class K const-qualified member function returning int

c++decl> explain int (K::*p)() &;
declare p as pointer to member of class K lvalue-reference-qualified member function returning int

c++decl> explain int (K::*p)() &&;
declare p as pointer to member of class K rvalue-reference-qualified member function returning int

c++decl> explain int (K::*p)() const &&;
declare p as pointer to member of class K const-qualified rvalue-reference-qualified member function returning int

c++decl> explain int (K::*p)() volatile;
declare p as pointer to member of class K volatile-qualified member function returning int

Function returning function parameter crash

Version: f7124b1

Reading symbols from c++decl...
(gdb) r 'explain void f(void ()())'
Starting program: /dev/shm/cdecl/src/c++decl 'explain void f(void ()())'
Missing separate debuginfos, use: zypper install glibc-debuginfo-2.35-1.1.x86_64
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x0000000000411df7 in yyparse () at /dev/shm/cdecl/src/parser.y:4702
4702          $$.ast->loc = @$;
Missing separate debuginfos, use: zypper install libncurses6-debuginfo-6.3.20220129-9.1.x86_64 libreadline8-debuginfo-8.1-3.1.x86_64
(gdb) bt
#0  0x0000000000411df7 in yyparse () at /dev/shm/cdecl/src/parser.y:4702
#1  0x0000000000427e73 in cdecl_parse_string (s=0x4e3e30 "explain void f(void ()())", s_len=25) at cdecl.c:399
#2  0x00000000004278e8 in cdecl_parse_command_line (command=0x0, argc=1, argv=0x7fffffffdba0) at cdecl.c:221
#3  0x00000000004277cc in cdecl_parse_argv (argc=1, argv=0x7fffffffdba0) at cdecl.c:187
#4  0x0000000000427730 in main (argc=1, argv=0x7fffffffdba0) at cdecl.c:148
(gdb) up
#1  0x0000000000427e73 in cdecl_parse_string (s=0x4e3e30 "explain void f(void ()())", s_len=25) at cdecl.c:399
399       int const status = yyparse() == 0 ? EX_OK : EX_DATAERR;
(gdb) 
#2  0x00000000004278e8 in cdecl_parse_command_line (command=0x0, argc=1, argv=0x7fffffffdba0) at cdecl.c:221
221       int const status = cdecl_parse_string( sbuf.str, sbuf.len );
(gdb) 
#3  0x00000000004277cc in cdecl_parse_argv (argc=1, argv=0x7fffffffdba0) at cdecl.c:187
187         return cdecl_parse_command_line( /*command=*/NULL, argc, argv );
(gdb) 
#4  0x0000000000427730 in main (argc=1, argv=0x7fffffffdba0) at cdecl.c:148
148       exit( cdecl_parse_argv( argc, argv ) );

Autoconf: `AC_PROG_LEX` warnings in 2.70

Building this project with autoconf 2.70 gives the following warning:

configure.ac:31: warning: AC_PROG_LEX without either yywrap or noyywrap is obsolete
./lib/autoconf/programs.m4:716: _AC_PROG_LEX is expanded from...
./lib/autoconf/programs.m4:709: AC_PROG_LEX is expanded from...
aclocal.m4:650: AM_PROG_LEX is expanded from...
m4/ax_prog_flex.m4:47: AX_PROG_FLEX is expanded from...
configure.ac:31: the top level

It appears that AC_PROG_LEX was updated in 2.70 to take a somewhat-required-ish parameter:
https://www.gnu.org/software/autoconf/manual/autoconf-2.70/html_node/Particular-Programs.html#index-AC_005fPROG_005fLEX-1

And it seems that AX_PROG_FLEX uses AC_PROG_LEX via AM_PROG_LEX; and ax_prog_flex.m4 hasn't yet been updated to deal with the new AC_PROG_LEX parameter.

Don't necessarily know whether there's a lot to do right now, since ax_prog_flex.m4 upstream is still using the legacy syntax. But in any case, it's something to be aware of, I suppose.

cdecl-9.4.tar.gz FTBFS

https://github.com/paul-j-lucas/cdecl/releases/download/cdecl-9.4/cdecl-9.4.tar.gz :

gcc -DHAVE_CONFIG_H -I.  -I../lib -I../lib -I/include   -g -O2  -Wall -Wcast-align -Wconversion -Wextra -Wfloat-equal -Wimplicit-fallthrough=4 -Wimplicit-fallthrough -Wno-unknown-warning-option -Wredundant-decls -Wshadow -Wsign-compare -Wsign-conversion -Wuninitialized -Wunreachable-code -Wunused -Wwrite-strings -MT parser.o -MD -MP -MF .deps/parser.Tpo -c -o parser.o parser.c
parser.y:55:10: fatal error: set_options.h: No such file or directory
   55 | #include "set_options.h"
      |          ^~~~~~~~~~~~~~~

DESTDIR not heeded during make install

First known bad version: cdecl-16.4
Last known good version: cdecl-16.3

Issue Type

  1. Build-time issue: you get either a compile-time error or warning while building cdecl.

Build-time Issue

What error or warning did you get?

$ make install DESTDIR=/tmp/rt
...
make[3]: Entering directory '~/cdecl-16.4/share/bash-completions/completions'
make[4]: Entering directory '~/cdecl-16.4/share/bash-completions/completions'
make[4]: Nothing to be done for 'install-exec-am'.
mkdir -p /usr/local/share/bash-completions/completions
mkdir: cannot create directory ‘/usr/local/share/bash-completions’: Permission denied
make[4]: *** [Makefile:1551: /usr/local/share/bash-completions/completions] Error 1

What compiler and version are you using?

gcc version 13.2.1 20240509 [revision b7a2697733d19a093cbdd0e200ffce069a4bc812] (SUSE Linux) amd64

What operating system and version (Linux, FreeBSD, macOS, etc.) are you building on?

Linux 6.9.0 amd64

FreeBSD port: Configure Failiure

I got the following trying to update from 8.0->11.2:

configure:4483: cc -V >&5
cc: error: argument to '-V' is missing (expected 1 value)
cc: error: no input files
configure:4494: $? = 1
configure:4483: cc -qversion >&5
cc: error: unknown argument '-qversion'; did you mean '--version'?
cc: error: no input files
configure:4494: $? = 1
configure:4483: cc -version >&5
cc: error: unknown argument '-version'; did you mean '--version'?
cc: error: no input files
configure:4494: $? = 1
configure:4514: checking whether the C compiler works
configure:4536: cc -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -I/usr/local/include -L/usr/local/lib -fstack-protector-strong conftest.c >&5
conftest.c:7:21: warning: missing terminating '"' character [-Winvalid-pp-token]
#define PACKAGE_URL "https://github.com/paul-j-lucas/cdecl
^
conftest.c:8:1: warning: missing terminating '"' character [-Winvalid-pp-token]
"
^
conftest.c:8:1: error: expected identifier or '('
2 warnings and 1 error generated.
configure:4540: $? = 1
configure:4578: result: no
configure: failed program was:
| /* confdefs.h /
| #define PACKAGE_NAME "cdecl"
| #define PACKAGE_TARNAME "cdecl"
| #define PACKAGE_VERSION "11.2"
| #define PACKAGE_STRING "cdecl 11.2"
| #define PACKAGE_BUGREPORT "https://github.com/paul-j-lucas/cdecl/issues"
| #define PACKAGE_URL "https://github.com/paul-j-lucas/cdecl
| "
| #define PACKAGE "cdecl"
| #define VERSION "11.2"
| /
end confdefs.h. */
|
| int
| main ()
| {
|
| ;
| return 0;
| }
configure:4583: error: in /home/ler/FreeBSD/ports/devel/cdecl/work/cdecl-cdecl-11.2': configure:4586: error: C compiler cannot create executables See config.log' for more details

help?

readline: deprecation warning.

--- autocomplete.o ---
autocomplete.c:381:39: warning: 'CPPFunction' is deprecated [-Wdeprecated-declarations]
rl_attempted_completion_function = (CPPFunction*)attempt_completion;
^
/usr/local/include/readline/rltypedefs.h:38:47: note: 'CPPFunction' has been explicitly marked deprecated here
typedef char **CPPFunction () attribute ((deprecated));
^

Latest stuff from FreeBSD ports head.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.