42School / norminette

Official 42 norminette
MIT License
944 stars 139 forks source link

C23 attribute syntax #316

Open mjy9088 opened 2 years ago

mjy9088 commented 2 years ago

Describe the bug

Not works with attribute syntax like C++11's, maybe from C23

Erroneous code

/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_exit.c                                          :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: Juyeong Maing <jmaing@student.42seoul.kr>  +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/05/02 14:10:15 by jmaing            #+#    #+#             */
/*   Updated: 2022/05/20 02:01:39 by Juyeong Maing    ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "ft_exit.h"

#include <stdbool.h>
#include <stdlib.h>

static void x(bool execute, void (*cleanup)())
{
    static void (*cleanup_func)() = NULL;

    if (!execute)
        cleanup_func = cleanup;
    else if (cleanup_func)
        cleanup_func();
}

#if __STDC_VERSION__ > 201710L

[[noreturn]]

#else
# if __STDC_VERSION__ >= 201112L

_Noreturn

# endif
#endif

int ft_exit(signed char status)
{
    x(true, NULL);
    exit((int) status);
}

void    ft_set_exit_handler(void (*cleanup)())
{
    x(false, cleanup);
}

result:

src/ft_exit.c: Error!
Error: TAB_INSTEAD_SPC      (line:  40, col:   4):      Found tab when expecting space
Error: TOO_MANY_TAB         (line:  43, col:   1):      Extra tabs for indent level
Error: NEWLINE_PRECEDES_FUNC (line:  44, col:   1):     Functions must be separated by a newline

Additional infos

Additional context

I want to suppress non-void function does not return a value in all control paths message from clang which is false positive.

W2Wizard commented 2 years ago

__attribute__((noreturn)) ?

mjy9088 commented 2 years ago

__attribute__((noreturn)) ?

It's not C standard, so I want to avoid it.

W2Wizard commented 2 years ago

You could use __declspec(noreturn), if I remember right there is a gcc flag that lets you compile your program with it.